Skip to content

Commit 034d4f4

Browse files
committed
special treate for return values of require
2nd should be unknown since Lua 5.3, otherwise should be nil #1868
1 parent eeb9ba0 commit 034d4f4

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
## 3.6.9
44
* `FIX` [#1864]
5+
* `FIX` [#1868]
56

67
[#1864]: https://github.com/sumneko/lua-language-server/issues/1864
8+
[#1868]: https://github.com/sumneko/lua-language-server/issues/1868
79

810
## 3.6.8
911
`2023-1-31`

script/vm/compiler.lua

+15
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,21 @@ local compilerSwitch = util.switch()
14841484
return
14851485
end
14861486
if func.special == 'require' then
1487+
if index == 2 then
1488+
local uri = guide.getUri(source)
1489+
local version = config.get(uri, 'Lua.runtime.version')
1490+
if version == 'Lua 5.3'
1491+
or version == 'Lua 5.4' then
1492+
vm.setNode(source, vm.declareGlobal('type', 'unknown'))
1493+
else
1494+
vm.setNode(source, vm.declareGlobal('type', 'nil'))
1495+
end
1496+
return
1497+
end
1498+
if index >= 3 then
1499+
vm.setNode(source, vm.declareGlobal('type', 'nil'))
1500+
return
1501+
end
14871502
if not args then
14881503
return
14891504
end

test/crossfile/infer.lua

+30
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,33 @@ print(<?X?>)
133133
]], },
134134
infer = 'boolean|integer',
135135
}
136+
137+
TEST {
138+
{ path = 'a.lua', content = [[
139+
return 1337, "string", true
140+
]], },
141+
{ path = 'b.lua', content = [[
142+
local <?a?>, b, c = require 'a
143+
]], },
144+
infer = 'integer',
145+
}
146+
147+
TEST {
148+
{ path = 'a.lua', content = [[
149+
return 1337, "string", true
150+
]], },
151+
{ path = 'b.lua', content = [[
152+
local a, <?b?>, c = require 'a
153+
]], },
154+
infer = 'unknown',
155+
}
156+
157+
TEST {
158+
{ path = 'a.lua', content = [[
159+
return 1337, "string", true
160+
]], },
161+
{ path = 'b.lua', content = [[
162+
local a, b, <?c?> = require 'a
163+
]], },
164+
infer = 'nil',
165+
}

0 commit comments

Comments
 (0)