diff --git a/changelog.md b/changelog.md index daefdb5ae..6a0cd696e 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `FIX` Unannotated functions that return a generic class instance (e.g. `Box`) returned from a call no longer show `|unknown` in their inferred return type ## 3.19.2 `2026-10-13` diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 20ab3ac41..b0a18c0fd 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -2248,6 +2248,10 @@ local compilerSwitch = util.switch() end goto CONTINUE end + if n.type == 'doc.type.sign' then + hasKnownType = true + break + end hasUnknownType = true ::CONTINUE:: end diff --git a/test/type_inference/common.lua b/test/type_inference/common.lua index 2fe6417d2..d60c1c50e 100644 --- a/test/type_inference/common.lua +++ b/test/type_inference/common.lua @@ -31,7 +31,7 @@ var = y TEST 'any' [[ function f() - + end ]] @@ -1536,7 +1536,7 @@ local mt = {} function mt:loop(callback) end mt:loop(function () - + end) ]] @@ -2684,7 +2684,7 @@ return function () if not t then return end - + print() end ]] @@ -2697,7 +2697,7 @@ f(function () if not t then return end - + print() end) ]] @@ -3439,7 +3439,7 @@ local n ---@type string local s -local = t[n] +local = t[n] local test2 = t[s] --test and test2 are unknow ]] @@ -3452,7 +3452,7 @@ local n ---@type string local s -local test = t[n] +local test = t[n] local = t[s] --test and test2 are unknow ]] @@ -5278,3 +5278,20 @@ local myClass local = myClass:pass(42) ]] + +TEST 'Box' [[ +---@class Box +---@field value T + +---@return Box +function make_box() + return { value = "x" } +end + +function wrap() + local b = make_box() + return b +end + +local = wrap() +]]