fix: resolve type aliases when lowering 'is' to Lua (#1149) - #1169
Merged
Conversation
Member
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #1149.
x is SomeTypecompiles to a runtime type check. When the tested type is a type alias, the code generator inspected the nominal type's owntypename("nominal") instead of the type it resolves to, sointegerandnilaliases were lowered like a generictype(x) == "..."check.x is Ashould lower tomath.type(x) == "integer"(anumbermay be a float, not an integer), andx is Btox == nil— exactly whatx is integer/x is nilalready produce.Fix
In both
is-lowering sites (teal/gen/lua_generator.tland the 5.1/5.3 compat header selection inteal/gen/lua_compat.tl), resolve the cast type through its nominal chain before discriminating oninteger/nil. Chained aliases (local type C = A) resolve too.Tests
Added a
util.genregression test inspec/lang/operator/is_spec.luaasserting 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 expectedmath.type(x) == "integer"; restoring it passes.Validation
Regenerated
.luaartifacts viamake selfbuildso the committed build matches the.tlsources. Happy to adjust.