Skip to content

Fix: reject built-in simple type with a trailing dotted name (e.g. number.x.y.z) - #1162

Merged
hishamhm merged 1 commit into
teal-language:mainfrom
youdie006:fix/1136-simple-type-dotted-name
Aug 26, 2026
Merged

hishamhm merged 1 commit into
teal-language:mainfrom
youdie006:fix/1136-simple-type-dotted-name

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

Fixes #1136.

Root cause

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 (which is not a simple type and takes the nominal path) correctly reports unknown 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 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.

Tests

Added a regression test in spec/lang/declaration/local_type_spec.lua asserting that number.x.y.z, string.a.b, integer.foo, and boolean.foo each report unknown 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/boolean still type-check; nil.x/any.x/self.x/thread.x still error cleanly with no crash; a real dotted record type and string.format are unaffected.

Thanks to @purplesyringa for the clear report.


This change was prepared with AI assistance and reviewed by me before submission.

Comment thread teal/ast.tl Outdated
-- 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).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this comment block, it is not necessary

@hishamhm hishamhm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@youdie006
youdie006 force-pushed the fix/1136-simple-type-dotted-name branch from 416ed7e to ef5869f Compare August 25, 2026 17:32
@youdie006

Copy link
Copy Markdown
Contributor Author

Comment block removed.

Since the generated Lua is tracked here, I removed the four blank padding lines the compiler had left in teal/ast.lua, teal.lua and tl.lua where those comment lines were, so the generated files stay line-aligned with ast.tl. The net diff is now two changed lines per file, and ast.tl and ast.lua sit at the same line number (1969) as they did before.

Disclosure: I use AI assistance in my work, and I review and verify everything before it goes out.

@hishamhm

Copy link
Copy Markdown
Member

@youdie006 thank you! But you shouldn't need AI to remove a comment 😅

@hishamhm
hishamhm merged commit b9c67a3 into teal-language:main Aug 26, 2026
@purplesyringa

Copy link
Copy Markdown
Contributor

thanks for merging :)

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.

[bug] number.x.y.z accepted as type equivalent to number

3 participants