diff --git a/spec/lang/code_gen/macroexp_spec.lua b/spec/lang/code_gen/macroexp_spec.lua index fd5530bf9..de4e96fcc 100644 --- a/spec/lang/code_gen/macroexp_spec.lua +++ b/spec/lang/code_gen/macroexp_spec.lua @@ -144,5 +144,55 @@ describe("macroexp code generation", function() print("yes") end ]])) + + it("can resolve __eq metamethod (regression test for #814)", util.gen([[ + local type R = record + x: number + y: number + + metamethod __lt: function(a: R, b: R) = macroexp(a: R, b: R) + return a.x < b.x + end + + metamethod __eq: function(a: R, b: R) = macroexp(a: R, b: R) + return a.x == b.x + end + end + + local r: R = { x = 10, y = 20 } + local s: R = { x = 10, y = 0 } + + if r > s then + print("yes") + end + + if r == s then + print("the 'x' fields are equal") + end + ]], [[ + + + + + + + + + + + + + + local r = { x = 10, y = 20 } + local s = { x = 10, y = 0 } + + if s.x < r.x then + print("yes") + end + + if r.x == s.x then + print("the 'x' fields are equal") + end + ]])) end) diff --git a/spec/lang/macroexp/where_spec.lua b/spec/lang/macroexp/where_spec.lua new file mode 100644 index 000000000..e69de29bb diff --git a/tl.lua b/tl.lua index 26fc2d18e..b4363773a 100644 --- a/tl.lua +++ b/tl.lua @@ -12408,9 +12408,9 @@ self:expand_type(node, values, elements) }) end if node.op.op == "==" or node.op.op == "~=" then - - - + if is_lua_table_type(ra) and is_lua_table_type(rb) then + self:check_metamethod(node, binop_to_metamethod[node.op.op], ra, rb, ua, ub) + end if ra.typename == "enum" and rb.typename == "string" then if not (rb.literal and ra.enumset[rb.literal]) then diff --git a/tl.tl b/tl.tl index 54db870c9..d5b2aa58a 100644 --- a/tl.tl +++ b/tl.tl @@ -12408,9 +12408,9 @@ do end if node.op.op == "==" or node.op.op == "~=" then --- if is_lua_table_type(ra) and is_lua_table_type(rb) then --- self:check_metamethod(node, binop_to_metamethod[node.op.op], ra, rb) --- end + if is_lua_table_type(ra) and is_lua_table_type(rb) then + self:check_metamethod(node, binop_to_metamethod[node.op.op], ra, rb, ua, ub) + end if ra is EnumType and rb is StringType then if not (rb.literal and ra.enumset[rb.literal]) then