Skip to content

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

Open
youdie006 wants to merge 1 commit into
teal-language:mainfrom
youdie006:fix/1136-simple-type-dotted-name
Open

Fix: reject built-in simple type with a trailing dotted name (e.g. number.x.y.z)#1162
youdie006 wants to merge 1 commit into
teal-language:mainfrom
youdie006:fix/1136-simple-type-dotted-name

Conversation

@youdie006

Copy link
Copy Markdown

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.

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

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

2 participants