From 760e4048010f0448f4c7299ac85ae9781f9232e8 Mon Sep 17 00:00:00 2001 From: rcklos Date: Fri, 1 Nov 2024 16:18:56 +0800 Subject: [PATCH 1/6] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20table=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/vm/type.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/script/vm/type.lua b/script/vm/type.lua index 3bc51cd84..8124c6b83 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -656,8 +656,7 @@ function vm.getTableValue(uri, tnode, knode, inversion) end end if field.type == 'tableexp' - and field.value - and field.tindex == 1 then + and field.value then if inversion then if vm.isSubType(uri, 'integer', knode) then result:merge(vm.compileNode(field.value)) From 69eda2a69a80add977a038cc779d42db8b0927ff Mon Sep 17 00:00:00 2001 From: rcklos Date: Fri, 1 Nov 2024 16:50:28 +0800 Subject: [PATCH 2/6] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index da0137de2..69fe0d885 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `FIX` Using variables to retrieve array elements always prompts the first element type ## 3.12.0 `2024-10-30` From 78530ad2f68565ad8d5cbfd465cf3e513ce0159c Mon Sep 17 00:00:00 2001 From: rcklos Date: Mon, 4 Nov 2024 10:46:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?[=E4=BF=AE=E6=94=B9]=20infer=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E5=B0=8F=E4=BA=8E=E9=85=8D=E7=BD=AEN=E7=9A=84?= =?UTF-8?q?=E5=88=97=E8=A1=A8value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 2 +- script/config/template.lua | 1 + script/vm/type.lua | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 69fe0d885..f030ebda6 100644 --- a/changelog.md +++ b/changelog.md @@ -2,7 +2,7 @@ ## Unreleased -* `FIX` Using variables to retrieve array elements always prompts the first element type +* `NEW` Setting: `Lua.type.inferTableSize`: A Small Table array can be infered ## 3.12.0 `2024-10-30` diff --git a/script/config/template.lua b/script/config/template.lua index a5823d842..40ec799ea 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -403,6 +403,7 @@ local template = { ['Lua.type.weakNilCheck'] = Type.Boolean >> false, ['Lua.type.inferParamType'] = Type.Boolean >> false, ['Lua.type.checkTableShape'] = Type.Boolean >> false, + ['Lua.type.inferTableSize'] = Type.Integer >> 10, ['Lua.doc.privateName'] = Type.Array(Type.String), ['Lua.doc.protectedName'] = Type.Array(Type.String), ['Lua.doc.packageName'] = Type.Array(Type.String), diff --git a/script/vm/type.lua b/script/vm/type.lua index d2b941231..eb258a726 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -655,8 +655,10 @@ function vm.getTableValue(uri, tnode, knode, inversion) end end end + local N = config.get(uri, "Lua.type.inferTableSize") if field.type == 'tableexp' - and field.value then + and field.value + and field.tindex <= N then if inversion then if vm.isSubType(uri, 'integer', knode) then result:merge(vm.compileNode(field.value)) @@ -666,6 +668,8 @@ function vm.getTableValue(uri, tnode, knode, inversion) result:merge(vm.compileNode(field.value)) end end + elseif field.tindex and field.tindex > N then + fprint("field.tindex = %s", field.tindex) end if field.type == 'varargs' then result:merge(vm.compileNode(field)) From 466aaba3b12c9d34a60c76ba856839c019097904 Mon Sep 17 00:00:00 2001 From: rcklos Date: Mon, 4 Nov 2024 11:18:26 +0800 Subject: [PATCH 4/6] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E7=9A=84=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/vm/type.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/script/vm/type.lua b/script/vm/type.lua index eb258a726..d7bcd9a02 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -668,8 +668,6 @@ function vm.getTableValue(uri, tnode, knode, inversion) result:merge(vm.compileNode(field.value)) end end - elseif field.tindex and field.tindex > N then - fprint("field.tindex = %s", field.tindex) end if field.type == 'varargs' then result:merge(vm.compileNode(field)) From 791e8fe80b397052a8ded52ee246753740834a03 Mon Sep 17 00:00:00 2001 From: rcklos Date: Mon, 4 Nov 2024 13:59:32 +0800 Subject: [PATCH 5/6] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=20=E5=B0=8F=E9=A9=BC?= =?UTF-8?q?=E5=B3=B0=E5=91=BD=E5=90=8D=E6=B3=95=E8=A7=84=E8=8C=83=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=8F=98=E9=87=8F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/vm/type.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/vm/type.lua b/script/vm/type.lua index d7bcd9a02..18aa154f0 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -655,10 +655,10 @@ function vm.getTableValue(uri, tnode, knode, inversion) end end end - local N = config.get(uri, "Lua.type.inferTableSize") + local inferSize = config.get(uri, "Lua.type.inferTableSize") if field.type == 'tableexp' and field.value - and field.tindex <= N then + and field.tindex <= inferSize then if inversion then if vm.isSubType(uri, 'integer', knode) then result:merge(vm.compileNode(field.value)) From 835516bdb5340d6b444cc0d319739768bd0ba830 Mon Sep 17 00:00:00 2001 From: rcklos Date: Tue, 5 Nov 2024 11:41:50 +0800 Subject: [PATCH 6/6] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=20=E5=8F=96=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=94=BE=E5=88=B0=E5=BE=AA=E7=8E=AF=E5=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/vm/type.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/vm/type.lua b/script/vm/type.lua index 18aa154f0..ae6cbd292 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -615,6 +615,7 @@ end ---@return vm.node? function vm.getTableValue(uri, tnode, knode, inversion) local result = vm.createNode() + local inferSize = config.get(uri, "Lua.type.inferTableSize") for tn in tnode:eachObject() do if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do @@ -655,7 +656,6 @@ function vm.getTableValue(uri, tnode, knode, inversion) end end end - local inferSize = config.get(uri, "Lua.type.inferTableSize") if field.type == 'tableexp' and field.value and field.tindex <= inferSize then