diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-21 22:19:26 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-21 22:19:26 +0800 |
commit | 7291440d890483f70ddd7ba00db483af0257b499 (patch) | |
tree | 27d2a33c88a2f7d8ef908297bc5d7e9771db68d7 /test/type_inference | |
parent | 8ba44c3e21ac761b88226fec0cc8a5347a4a5804 (diff) | |
parent | a19f2ee7394c5f5a10342a37497fbd7b7587316c (diff) | |
download | lua-language-server-7291440d890483f70ddd7ba00db483af0257b499.zip |
Merge remote-tracking branch 'origin/type-narrow'
Diffstat (limited to 'test/type_inference')
-rw-r--r-- | test/type_inference/init.lua | 213 |
1 files changed, 207 insertions, 6 deletions
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index b63e03c1..7cab5ff3 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -77,12 +77,6 @@ function f(<?x?>) end ]] -TEST 'number' [[ -local <?var?> -var = 1 -var = 1.0 -]] - TEST 'string' [[ local var = '111' t.<?x?> = var @@ -95,6 +89,11 @@ var = '111' TEST 'string' [[ local var +<?var?> = '111' +]] + +TEST 'string' [[ +local var var = '111' print(<?var?>) ]] @@ -1521,3 +1520,205 @@ local AAA local <?x?> = AAA() ]] + +TEST 'string|integer' [[ +local <?x?> +x = '1' +x = 1 +]] + +TEST 'string' [[ +local x +<?x?> = '1' +x = 1 +]] + +TEST 'integer' [[ +local x +x = '1' +<?x?> = 1 +]] + +TEST 'string|integer' [[ +local x +print(<?x?>) +x = '1' +x = 1 +]] + +TEST 'string' [[ +local x +x = '1' +print(<?x?>) +x = 1 +]] + +TEST 'integer' [[ +local x +x = '1' +x = 1 +print(<?x?>) +]] + +TEST 'unknown' [[ +local x + +function A() + print(<?x?>) +end +]] + +TEST 'string|integer' [[ +local x + +function A() + print(<?x?>) +end + +x = '1' +x = 1 +]] + +TEST 'string' [[ +local x + +x = '1' + +function A() + print(<?x?>) +end + +x = 1 +]] + +TEST 'integer' [[ +local x + +x = '1' +x = 1 + +function A() + print(<?x?>) +end + +]] + +TEST 'boolean' [[ +local x + +function A() + x = true + print(<?x?>) +end + +x = '1' +x = 1 +]] + +TEST 'string|integer' [[ +local x + +function A() + x = true +end + +print(<?x?>) +x = '1' +x = 1 +]] + +TEST 'boolean' [[ +local x + +function A() + x = true + function B() + print(<?x?>) + end +end + +x = '1' +x = 1 +]] + +TEST 'table' [[ +local x + +function A() + x = true + function B() + x = {} + print(<?x?>) + end +end + +x = '1' +x = 1 +]] + +TEST 'boolean' [[ +local x + +function A() + x = true + function B() + x = {} + end + print(<?x?>) +end + +x = '1' +x = 1 +]] + +TEST 'string|integer' [[ +local x + +function A() + x = true + function B() + x = {} + end +end + +function C() + print(<?x?>) +end + +x = '1' +x = 1 +]] + +TEST 'integer?' [[ +---@type integer? +local <?x?> +]] + +TEST 'integer?' [[ +---@type integer? +local x + +if <?x?> then + print(x) +end +]] + +TEST 'integer' [[ +---@type integer? +local x + +if x then + print(<?x?>) +end +]] + +TEST 'integer?' [[ +---@type integer? +local x + +if x then + print(x) +end + +print(<?x?>) +]] |