emit_bin_vals lowered every pointer-typed ==/!= to @lp_str_eq, so two distinct records compared their bytes up to the first zero byte. Content compare now needs both sides to be text (string, or the untyped pointer/ptr runtime code carries text in); other references use icmp eq ptr, and string vs a non-text reference is a compile error. Adds selfhost/tests/identity.ludic; both seeds regenerated. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
21 lines
759 B
Text
21 lines
759 B
Text
program T {
|
|
# `==` / `!=` on two references is identity; only strings compare by content.
|
|
# The records below start with a zero/equal field, which a byte compare would
|
|
# have called equal.
|
|
property Thing { kind: int = 0, name: string = "" }
|
|
entry {
|
|
let a = new Thing
|
|
let b = new Thing
|
|
print(a == b) # 0: distinct records, same (zero) leading field
|
|
print(a == a) # 1: the same record
|
|
a.kind = 3
|
|
b.kind = 3
|
|
print(a != b) # 1: equal fields, still distinct
|
|
let c = a
|
|
print(c == a) # 1: an alias is the same record
|
|
let xs: []Thing = [a, b]
|
|
print(xs[1] == b) # 1: identity through a slice
|
|
let s = "ab"
|
|
print(s + "c" == "abc") # 1: strings still compare by content
|
|
}
|
|
}
|