Skip to content

fix: resolve type aliases when lowering 'is' to Lua (#1149) - #1169

Merged
hishamhm merged 1 commit into
teal-language:mainfrom
chiliec:fix-is-type-alias-lowering
Sep 5, 2026
Merged

fix: resolve type aliases when lowering 'is' to Lua (#1149)#1169
hishamhm merged 1 commit into
teal-language:mainfrom
chiliec:fix-is-type-alias-lowering

Conversation

@chiliec

@chiliec chiliec commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What

Closes #1149.

x is SomeType compiles to a runtime type check. When the tested type is a type alias, the code generator inspected the nominal type's own typename ("nominal") instead of the type it resolves to, so integer and nil aliases were lowered like a generic type(x) == "..." check.

local x: any = nil
local type A = integer
print(x is A)   -- was: type(x) == "number"   (wrong)
local type B = nil
print(x is B)   -- was: type(x) == "nil"      (wrong)

x is A should lower to math.type(x) == "integer" (a number may be a float, not an integer), and x is B to x == nil — exactly what x is integer / x is nil already produce.

Fix

In both is-lowering sites (teal/gen/lua_generator.tl and the 5.1/5.3 compat header selection in teal/gen/lua_compat.tl), resolve the cast type through its nominal chain before discriminating on integer / nil. Chained aliases (local type C = A) resolve too.

Tests

Added a util.gen regression test in spec/lang/operator/is_spec.lua asserting alias and direct forms lower identically.

Verified genuine RED→GREEN: reverting the source fix (keeping the test) makes it fail with type(x) == "number" vs the expected math.type(x) == "integer"; restoring it passes.

Validation

make selfbuild            # two-stage bootstrap diff clean
busted spec/lang          # 1733 successes / 0 failures
busted spec/api           # 96 successes / 0 failures
busted spec/cli           # 112 successes / 0 failures

Regenerated .lua artifacts via make selfbuild so the committed build matches the .tl sources. Happy to adjust.

@hishamhm

hishamhm commented Sep 5, 2026

Copy link
Copy Markdown
Member

Thank you!

@hishamhm
hishamhm merged commit cba0657 into teal-language:main Sep 5, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

is handles type aliases of integer incorrectly and nil inconsistently

2 participants