Skip to content

Commit

Permalink
fix: accept record method declaration for nested records
Browse files Browse the repository at this point in the history
Fixes #648.
  • Loading branch information
hishamhm committed Apr 27, 2023
1 parent 86278ca commit 0bdec77
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spec/declaration/record_method_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ describe("record method", function()
local ok = r.z:f(3, "abc")
]]))

it("nested declaration for record (regression test for #648)", util.check([[
local record Math
record Point
x: number
y: number
end
end
function Math.Point:move(dx: number, dy: number)
self.x = self.x + dx
self.y = self.y + dy
end
]]))

it("nested declaration in {}", util.check([[
local r = {
z = {},
Expand Down
3 changes: 2 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8062,7 +8062,8 @@ tl.type_check = function(ast, opts)
return nil, nil, dname
end
t = t and t.fields and t.fields[fname]
return t, v, dname

return t.def or t, v, dname
end
end

Expand Down
3 changes: 2 additions & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -8062,7 +8062,8 @@ tl.type_check = function(ast: Node, opts: TypeCheckOptions): Result, string
return nil, nil, dname
end
t = t and t.fields and t.fields[fname]
return t, v, dname

return t.def or t, v, dname
end
end

Expand Down

0 comments on commit 0bdec77

Please sign in to comment.