Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions spec/lang/declaration/local_type_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,16 @@ describe("local type", function()
]], {
{ y = 14, msg = 'in record field: Data: string "invalid" is not a member of MyEnum' }
}))

it("does not accept a built-in simple type followed by a dotted name (regression test for #1136)", util.check_type_error([[
local a: number.x.y.z = 1
local b: string.a.b = "x"
local c: integer.foo = 1
local d: boolean.foo = true
]], {
{ y = 1, msg = "unknown type number.x.y.z" },
{ y = 2, msg = "unknown type string.a.b" },
{ y = 3, msg = "unknown type integer.foo" },
{ y = 4, msg = "unknown type boolean.foo" },
}))
end)
7 changes: 6 additions & 1 deletion teal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,12 @@ end
parse_simple_type_or_nominal = function(state, block)
local tk = block.tk
local st = simple_types[tk]
if st then




local rest = block[reader.BLOCK_INDEXES.NOMINAL_TYPE.NAME + 1]
if st and not (rest and rest.kind == "identifier") then
return new_type(state, block, tk)
elseif tk == "table" and block.kind ~= "nominal_type" then
local typ = new_type(state, block, "map")
Expand Down
7 changes: 6 additions & 1 deletion teal/ast.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,12 @@ end
parse_simple_type_or_nominal = function(state, block)
local tk = block.tk
local st = simple_types[tk]
if st then




local rest = block[reader.BLOCK_INDEXES.NOMINAL_TYPE.NAME + 1]
if st and not (rest and rest.kind == "identifier") then
return new_type(state, block, tk)
elseif tk == "table" and block.kind ~= "nominal_type" then
local typ = new_type(state, block, "map")
Expand Down
7 changes: 6 additions & 1 deletion teal/ast.tl
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,12 @@ end
parse_simple_type_or_nominal = function(state: ParseState, block: Block): FirstOrderType
local tk = block.tk
local st = simple_types[tk as TypeName]
if st then
-- 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

local rest = block[reader.BLOCK_INDEXES.NOMINAL_TYPE.NAME + 1]
if st and not (rest and rest.kind == "identifier") then
return new_type(state, block, tk as TypeName) as StructuralType
elseif tk == "table" and block.kind ~= "nominal_type" then -- reader already turns plain `table` into map_type
local typ = new_type(state, block, "map") as MapType
Expand Down
7 changes: 6 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,12 @@ end
parse_simple_type_or_nominal = function(state, block)
local tk = block.tk
local st = simple_types[tk]
if st then




local rest = block[reader.BLOCK_INDEXES.NOMINAL_TYPE.NAME + 1]
if st and not (rest and rest.kind == "identifier") then
return new_type(state, block, tk)
elseif tk == "table" and block.kind ~= "nominal_type" then
local typ = new_type(state, block, "map")
Expand Down
Loading