|
| 1 | +--- |
| 2 | +source: tests/tests.rs |
| 3 | +expression: "format(&contents, LuaVersion::Luau)" |
| 4 | +input_file: tests/inputs-luau-full_moon/type_instantiations.lua |
| 5 | +--- |
| 6 | +--[[ |
| 7 | + |
| 8 | +Taken from https://github.com/luau-lang/luau/blob/535f92589bdc304c8a2012d6cfad5e7b9faff2f7/tests/conformance/explicit_type_instantiations.luau |
| 9 | + |
| 10 | +MIT License |
| 11 | + |
| 12 | +Copyright (c) 2019-2025 Roblox Corporation |
| 13 | +Copyright (c) 1994–2019 Lua.org, PUC-Rio. |
| 14 | + |
| 15 | +Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 16 | +this software and associated documentation files (the "Software"), to deal in |
| 17 | +the Software without restriction, including without limitation the rights to |
| 18 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 19 | +of the Software, and to permit persons to whom the Software is furnished to do |
| 20 | +so, subject to the following conditions: |
| 21 | + |
| 22 | +The above copyright notice and this permission notice shall be included in all |
| 23 | +copies or substantial portions of the Software. |
| 24 | + |
| 25 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 28 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 29 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 30 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | +SOFTWARE. |
| 32 | + |
| 33 | +]] |
| 34 | + |
| 35 | +-- Tests to ensure explicit type instantiations don't change runtime behavior |
| 36 | +local function identity<T>(x: T): T |
| 37 | + return x |
| 38 | +end |
| 39 | + |
| 40 | +assert(identity<<number>>(1) == 1) |
| 41 | + |
| 42 | +local function multipleReturns<T>(x: T): (T, T) |
| 43 | + return x, x |
| 44 | +end |
| 45 | + |
| 46 | +local a, b = multipleReturns<<number>>(1) |
| 47 | +assert(a == 1 and b == 1) |
| 48 | + |
| 49 | +local function typePacks<T...>(...: T...): T... |
| 50 | + return ... |
| 51 | +end |
| 52 | + |
| 53 | +local a, b = typePacks<<(string, number)>>(1, "a") |
| 54 | +assert(a == 1 and b == "a") |
| 55 | + |
| 56 | +local t = {} |
| 57 | +function t:method<T>(x: T): T |
| 58 | + assert(self == t) |
| 59 | + return x |
| 60 | +end |
| 61 | + |
| 62 | +assert(t:method(1) == 1) |
| 63 | + |
| 64 | +function t:methodTypePacks<T...>(...: T...): T... |
| 65 | + assert(self == t) |
| 66 | + return ... |
| 67 | +end |
| 68 | + |
| 69 | +local a, b = t:methodTypePacks<<(string, number)>>(1, "a") |
| 70 | +assert(a == 1 and b == "a") |
| 71 | + |
| 72 | +-- full-moon tests |
| 73 | +local complicatedExpr = expr<<A<B<C>>>>() |
| 74 | +local complicatedMethod = a:method<<A<B<C>>>>() |
| 75 | + |
| 76 | +return "OK" |
0 commit comments