Fix: reject built-in simple type with a trailing dotted name (e.g. number.x.y.z) - #1162
Conversation
| -- Only short-circuit to the built-in simple type when there is no trailing | ||
| -- dotted name part. Otherwise fall through to the nominal path below so that | ||
| -- an invalid annotation like `number.x.y.z` is reported as an unknown type | ||
| -- instead of being silently accepted as `number` (issue #1136). |
There was a problem hiding this comment.
please remove this comment block, it is not necessary
hishamhm
left a comment
There was a problem hiding this comment.
happy to merge this once the unnecessary comment is removed
parse_simple_type_or_nominal in teal/ast.tl short-circuits on a built-in simple type (number/string/integer/boolean/thread/any/self) and discards any trailing dotted name parts. As a result an invalid annotation like `local x: number.x.y.z = 1` is accepted as number and type-checks with no errors, while table.x.y.z (not a simple type, nominal path) correctly reports unknown type table.x.y.z. Only take the simple-type short-circuit when there is no dotted continuation (block[NOMINAL_TYPE.NAME + 1] is not an identifier); otherwise fall through to the existing nominal path, which reports the unknown type. Ran make to regenerate the .lua artifacts (teal/ast.lua, tl.lua, teal.lua) from the .tl source per the repo's codegen convention. Fixes teal-language#1136.
416ed7e to
ef5869f
Compare
|
Comment block removed. Since the generated Lua is tracked here, I removed the four blank padding lines the compiler had left in Disclosure: I use AI assistance in my work, and I review and verify everything before it goes out. |
|
@youdie006 thank you! But you shouldn't need AI to remove a comment 😅 |
|
thanks for merging :) |
Fixes #1136.
Root cause
parse_simple_type_or_nominalinteal/ast.tlshort-circuits on a built-in simple type (number/string/integer/boolean/thread/any/self) and discards any trailing dotted name parts. As a result an invalid annotation likelocal x: number.x.y.z = 1is accepted asnumberand type-checks with no errors, whiletable.x.y.z(which is not a simple type and takes the nominal path) correctly reportsunknown type table.x.y.z.Fix
Only take the simple-type short-circuit when there is no dotted continuation (
block[NOMINAL_TYPE.NAME + 1]is not anidentifier). Otherwise fall through to the existing nominal path, which reports the unknown type. Ranmaketo regenerate the.luaartifacts (teal/ast.lua,tl.lua,teal.lua) from the.tlsource per the repo's codegen convention.Tests
Added a regression test in
spec/lang/declaration/local_type_spec.luaasserting thatnumber.x.y.z,string.a.b,integer.foo, andboolean.fooeach reportunknown type ...(4 type errors, 0 syntax errors).Verified red/green with busted (test fails before the fix, passes after) and the full suite passes (1928 successes / 0 failures). Plain
number/string/integer/booleanstill type-check;nil.x/any.x/self.x/thread.xstill error cleanly with no crash; a real dotted record type andstring.formatare unaffected.Thanks to @purplesyringa for the clear report.
This change was prepared with AI assistance and reviewed by me before submission.