| 1 | // Regression test for https://github.com/vlang/v/issues/27089 |
| 2 | // Comparing a stored reference with `&expr` should compare addresses, |
| 3 | // not perform a deep struct equality check. |
| 4 | struct Data { |
| 5 | mut: |
| 6 | a f32 |
| 7 | b int |
| 8 | c string |
| 9 | } |
| 10 | |
| 11 | struct Holder { |
| 12 | mut: |
| 13 | buf Data |
| 14 | ref &Data = unsafe { nil } |
| 15 | } |
| 16 | |
| 17 | fn test_address_of_field_compares_addresses() { |
| 18 | mut t := Holder{} |
| 19 | // `t.ref` is nil, so address comparison must be true (nil != &t.buf). |
| 20 | assert t.ref != &t.buf |
| 21 | t.ref = &t.buf |
| 22 | // Now both refer to the same address. |
| 23 | assert t.ref == &t.buf |
| 24 | other := Data{} |
| 25 | // Different addresses with structurally equal contents must still be unequal. |
| 26 | assert &other != &t.buf |
| 27 | } |
| 28 | |