diff options
-rw-r--r-- | script/core/diagnostics/assign-type-mismatch.lua | 1 | ||||
-rw-r--r-- | script/vm/compiler.lua | 14 | ||||
-rw-r--r-- | script/vm/infer.lua | 10 | ||||
-rw-r--r-- | script/vm/type.lua | 12 | ||||
-rw-r--r-- | test/diagnostics/type-check.lua | 17 | ||||
-rw-r--r-- | test/type_inference/init.lua | 7 |
6 files changed, 53 insertions, 8 deletions
diff --git a/script/core/diagnostics/assign-type-mismatch.lua b/script/core/diagnostics/assign-type-mismatch.lua index 8080b2ec..e84e41df 100644 --- a/script/core/diagnostics/assign-type-mismatch.lua +++ b/script/core/diagnostics/assign-type-mismatch.lua @@ -5,6 +5,7 @@ local vm = require 'vm' local await = require 'await' local checkTypes = { + 'local', 'setlocal', 'setglobal', 'setfield', diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 46f6d0e9..ff1d9259 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1000,14 +1000,12 @@ local function compileLocal(source) end end local hasMarkValue - if source.value then - if not hasMarkDoc or guide.isLiteral(source.value) then - hasMarkValue = true - if source.value.type == 'table' then - vm.setNode(source, source.value) - elseif source.value.type ~= 'nil' then - vm.setNode(source, vm.compileNode(source.value)) - end + if not hasMarkDoc and source.value then + hasMarkValue = true + if source.value.type == 'table' then + vm.setNode(source, source.value) + elseif source.value.type ~= 'nil' then + vm.setNode(source, vm.compileNode(source.value)) end end -- function x.y(self, ...) --> function x:y(...) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 25165de6..1f77b638 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -266,6 +266,16 @@ function mt:_eraseAlias(uri) end end end + if set.type == 'doc.class' then + if set.extends then + for _, ext in ipairs(set.extends) do + if ext.type == 'doc.extends.name' then + local view = ext[1] + drop[view] = true + end + end + end + end end LOCK[n.name] = nil ::CONTINUE:: diff --git a/script/vm/type.lua b/script/vm/type.lua index d132619c..7eb1b06f 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -171,6 +171,18 @@ function vm.isSubType(uri, child, parent, mark) mark[childName] = nil end + --[[ + ---@class A: string + + ---@type A + local x = '' --> `string` set to `A` + ]] + if guide.isBasicType(childName) + and guide.isLiteral(child) + and vm.isSubType(uri, parentName, childName) then + return true + end + return false end diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 711211e8..34f7a492 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -479,5 +479,22 @@ n = nb ]] config.set(nil, 'Lua.type.weakUnionCheck', false) +TEST [[ +---@class Option: string + +---@param x Option +local function f(x) end + +---@type Option +local x = 'aaa' + +f(x) +]] + +TEST [[ +---@type number +local <!x!> = 'aaa' +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 7b4185d7..4b745c0d 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3142,3 +3142,10 @@ for _ in _ do end print(<?s?>) ]] + +TEST 'A' [[ +---@class A: string + +---@type A +local <?s?> = '' +]] |