Skip to content

Commit

Permalink
fix: eager resolution of unused type arguments
Browse files Browse the repository at this point in the history
Fixes #881.
  • Loading branch information
hishamhm committed Dec 31, 2024
1 parent fd5c41d commit 44ced6a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spec/lang/subtyping/typealias_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ describe("typealias", function()
end
end
]]))

it("resolves early even if type arguments are not used (regression test for #881)", util.check([[
local record Foo<T> end
local record Bar<T> end
local type StringFoo = Foo<string>
local type StringBar = Bar<string>
local type Test = {StringFoo: StringBar}
local test: Test = {}
]]))
end)
6 changes: 6 additions & 0 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7649,6 +7649,12 @@ do
copy.constraint, same = resolve(t.constraint, same)
end
end


local rt = fn_var(self, a_type(t, "typevar", { typevar = t.typearg }))
if rt then
resolved[t.typearg] = rt
end
elseif t.typename == "unresolvable_typearg" then
assert(copy.typename == "unresolvable_typearg")
copy.typearg = t.typearg
Expand Down
6 changes: 6 additions & 0 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -7649,6 +7649,12 @@ do
copy.constraint, same = resolve(t.constraint, same)
end
end

-- eager resolution of type argument variables
local rt = fn_var(self, a_type(t, "typevar", { typevar = t.typearg } as TypeVarType))
if rt then
resolved[t.typearg] = rt
end
elseif t is UnresolvableTypeArgType then
assert(copy is UnresolvableTypeArgType)
copy.typearg = t.typearg
Expand Down

0 comments on commit 44ced6a

Please sign in to comment.