Commit ed6b75ed

ed6b75edcd21Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified

Description

Merge pull request #1490 from ryanseys/rs-object-identity-eq

Compare objects without a custom == by object identity

Details

Commit
ed6b75edcd21
Parent
1de81c21d7a8
Merge parent
a1eb5a78f390

src/codegen_call.cmodifiedView file

@@ -7813,6 +7813,23 @@
78137813 buf_printf(b, " %s NULL)", eq ? "==" : "!=");
78147814 return;
78157815 }
7816+ /* object == object with no user-defined == or <=>: Object#== identity.
7817+ Pointer-backed objects compare by address -- faithful to CRuby, where two
7818+ distinct instances are never == and an instance is == only to itself. A
7819+ value-type object has no stable identity (it is copied by value), so
7820+ identity is unrepresentable; rather than silently diverge (structural
7821+ equality would say true where CRuby says false) we refuse and ask for an
7822+ explicit ==. */
7823+ if (recv >= 0 && ty_is_object(rt) && ty_is_object(a0)) {
7824+ if (comp_ty_value_obj(c, rt) || comp_ty_value_obj(c, a0))
7825+ unsupported(c, id, "equality on a value-type object without a user-defined == (define == for comparison)");
7826+ buf_puts(b, "((void *)(");
7827+ emit_expr(c, recv, b);
7828+ buf_printf(b, ") %s (void *)(", eq ? "==" : "!=");
7829+ emit_expr(c, argv[0], b);
7830+ buf_puts(b, "))");
7831+ return;
7832+ }
78167833 unsupported(c, id, "equality");
78177834 }
78187835