From 0bdec774a91854cf661c05b1b806bd594437eb8c Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 27 Apr 2023 10:09:22 -0300 Subject: [PATCH] fix: accept record method declaration for nested records Fixes #648. --- spec/declaration/record_method_spec.lua | 14 ++++++++++++++ tl.lua | 3 ++- tl.tl | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spec/declaration/record_method_spec.lua b/spec/declaration/record_method_spec.lua index f30fa7205..a9f0c3632 100644 --- a/spec/declaration/record_method_spec.lua +++ b/spec/declaration/record_method_spec.lua @@ -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 = {}, diff --git a/tl.lua b/tl.lua index 332e9af1b..6fb47fe43 100644 --- a/tl.lua +++ b/tl.lua @@ -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 diff --git a/tl.tl b/tl.tl index 2e564369f..b82ffdb02 100644 --- a/tl.tl +++ b/tl.tl @@ -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