Skip to content

Commit 72fccb7

Browse files
committed
resolve #1244 call.return check as
1 parent c18f88d commit 72fccb7

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

script/vm/compiler.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local vm = require 'vm.vm'
1111
---@field _node vm.node
1212
---@field _globalBase table
1313
---@field cindex integer
14+
---@field func parser.object
1415

1516
-- 该函数有副作用,会给source绑定node!
1617
local function bindDocs(source)
@@ -557,11 +558,15 @@ local function getReturn(func, index, args)
557558
func._callReturns = {}
558559
end
559560
if not func._callReturns[index] then
561+
local call = func.parent
560562
func._callReturns[index] = {
561563
type = 'call.return',
562-
parent = func,
564+
parent = call,
565+
func = func,
563566
cindex = index,
564567
args = args,
568+
start = call.start,
569+
finish = call.finish,
565570
}
566571
end
567572
return vm.compileNode(func._callReturns[index])
@@ -1531,7 +1536,10 @@ local compilerSwitch = util.switch()
15311536
: case 'call.return'
15321537
---@param source parser.object
15331538
: call(function (source)
1534-
local func = source.parent
1539+
if bindAs(source) then
1540+
return
1541+
end
1542+
local func = source.func
15351543
local args = source.args
15361544
local index = source.cindex
15371545
if func.special == 'setmetatable' then

test/type_inference/init.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,14 +3219,14 @@ end
32193219
local <?x?> = n or 0
32203220
]]
32213221

3222-
--TEST 'number' [=[
3223-
--local <?x?> = F()--[[@as number]]
3224-
--]=]
3225-
--
3226-
--TEST 'number' [=[
3227-
--local function f()
3228-
-- return F()--[[@as number]]
3229-
--end
3230-
--
3231-
--local <?x?> = f()
3232-
--]=]
3222+
TEST 'number' [=[
3223+
local <?x?> = F()--[[@as number]]
3224+
]=]
3225+
3226+
TEST 'number' [=[
3227+
local function f()
3228+
return F()--[[@as number]]
3229+
end
3230+
3231+
local <?x?> = f()
3232+
]=]

0 commit comments

Comments
 (0)