From 10275c3667256e720371ce5280658c3e4f950d2f Mon Sep 17 00:00:00 2001 From: fesily Date: Tue, 16 Jan 2024 13:38:52 +0800 Subject: automatic derivation function param type --- script/vm/compiler.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'script/vm/compiler.lua') diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 8a1fa96a..7e12c32a 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1090,6 +1090,37 @@ local function compileLocal(source) end end end + if not hasDocArg + and func.parent.type == 'local' then + local refs = vm.getRefs(func, function (_) + return false + end) + local findCall + if refs then + for i, ref in ipairs(refs) do + if ref.parent.type == 'call' then + findCall = ref.parent + break + end + end + end + if findCall and findCall.args then + local index + for i, arg in ipairs(source.parent) do + if arg == source then + index = i + break + end + end + if index then + local callerArg = findCall.args[index] + if callerArg then + hasDocArg = true + vm.setNode(source, vm.compileNode(callerArg)) + end + end + end + end if not hasDocArg then vm.setNode(source, vm.declareGlobal('type', 'any')) end -- cgit v1.2.3 From 259d21f66c34468e7d7860d87463e586ef805892 Mon Sep 17 00:00:00 2001 From: fesily Date: Tue, 16 Jan 2024 13:41:20 +0800 Subject: compileLocal add async --- script/vm/compiler.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'script/vm/compiler.lua') diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 7e12c32a..96db7051 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1030,6 +1030,7 @@ local function compileForVars(source, target) return false end +---@async ---@param source parser.object local function compileLocal(source) local myNode = vm.setNode(source, source) -- cgit v1.2.3 From a90d1d2c4990fed2db4ac5b2341ff12193389c1c Mon Sep 17 00:00:00 2001 From: fesily Date: Wed, 17 Jan 2024 17:16:48 +0800 Subject: use func.parent.ref --- script/vm/compiler.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'script/vm/compiler.lua') diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 96db7051..2222fa9b 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1030,7 +1030,6 @@ local function compileForVars(source, target) return false end ----@async ---@param source parser.object local function compileLocal(source) local myNode = vm.setNode(source, source) @@ -1093,9 +1092,7 @@ local function compileLocal(source) end if not hasDocArg and func.parent.type == 'local' then - local refs = vm.getRefs(func, function (_) - return false - end) + local refs = func.parent.ref local findCall if refs then for i, ref in ipairs(refs) do -- cgit v1.2.3