Skip to content

Commit

Permalink
fix error when matching against undefined types
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Jan 12, 2025
1 parent b2176c4 commit 6751278
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
13 changes: 13 additions & 0 deletions spec/lang/subtyping/interface_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,19 @@ describe("subtyping of interfaces:", function()
print(foo:get_value())
]]))

it("regression test when matching against an unknown type", util.check_type_error([[
local interface B
end
local x: B
if x is W then
end
]], {
{ msg = "x (of type B) can never be a W" },
{ msg = "unknown type W" },
}))

it("regression test for #830", util.check_lines([[
local interface IFoo
end
Expand Down
6 changes: 4 additions & 2 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8830,8 +8830,10 @@ do
end

local function a_is_interface_b(self, a, b)
assert(a.found)
assert(b.found)
if (not a.found) or (not b.found) then
return false
end

local af = a.found.def
if af.typename == "generic" then
af = self:apply_generic(a, af, a.typevals)
Expand Down
6 changes: 4 additions & 2 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -8830,8 +8830,10 @@ do
end

local function a_is_interface_b(self: TypeChecker, a: NominalType, b: NominalType): boolean, {Error}
assert(a.found)
assert(b.found)
if (not a.found) or (not b.found) then
return false
end

local af = a.found.def
if af is GenericType then
af = self:apply_generic(a, af, a.typevals)
Expand Down

0 comments on commit 6751278

Please sign in to comment.