Commit a1eb5a78
a1eb5a78f390Merged
Ryan Seys <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
codegen: emit Object#== identity for objects without a custom ==
Comparing two user objects with == or != where the class chain defines
neither == nor <=> previously fell through the equality gate and aborted
compilation. CRuby's fallback is Object#==, which is object identity: an
instance is equal only to itself, and two distinct instances are never equal.
Emit that fallback as a pointer comparison for pointer-backed objects, which
reproduces CRuby exactly. Value-type objects are copied by value and have no
stable identity, so identity is unrepresentable; rather than silently diverge
(structural equality would report equal where CRuby reports not-equal) the gate
now rejects them with a message asking for an explicit ==, which already
dispatches when defined.
Gates: 951 tests pass; bootstrap IR+C fixpoint byte-identical for analyze and codegen.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- a1eb5a78f390
- Parent
- 913a83318df6
src/codegen_call.cmodifiedView file
buf_printf(b, " %s NULL)", eq ? "==" : "!="); return; } /* object == object with no user-defined == or <=>: Object#== identity. Pointer-backed objects compare by address -- faithful to CRuby, where two distinct instances are never == and an instance is == only to itself. A value-type object has no stable identity (it is copied by value), so identity is unrepresentable; rather than silently diverge (structural equality would say true where CRuby says false) we refuse and ask for an explicit ==. */ if (recv >= 0 && ty_is_object(rt) && ty_is_object(a0)) { if (comp_ty_value_obj(c, rt) || comp_ty_value_obj(c, a0)) unsupported(c, id, "equality on a value-type object without a user-defined == (define == for comparison)"); buf_puts(b, "((void *)("); emit_expr(c, recv, b); buf_printf(b, ") %s (void *)(", eq ? "==" : "!="); emit_expr(c, argv[0], b); buf_puts(b, "))"); return; } unsupported(c, id, "equality"); }test/object_identity_eq.rbaddedView file
Loading diff…
test/object_identity_eq.rb.expectedaddedView file
Loading diff…