Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cgen: fix comparing interface values of structs containing optional r…
- Loading branch information
Showing
2 changed files
with
27 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 21 additions & 4 deletions
25
vlib/v/tests/interface_eq_methods_with_option_and_ref_test.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
// for issue 19441 | ||
// for issue 19441, 20212. | ||
// The issue 19441 manifests itself in the following way: | ||
// when the Mixin struct is present in the code, it causes a cgen error, | ||
// and when the Mixin struct is not included, the eq method results causes the final assertion to fail | ||
pub interface Iface {} | ||
|
||
pub struct Derived {} | ||
// test ref | ||
pub struct Derived { | ||
field1 &Iface = unsafe { nil } | ||
} | ||
|
||
// test option and ref | ||
pub struct Struct { | ||
field ?&Iface | ||
field2 ?&Iface | ||
} | ||
|
||
// test non-ref and embeded | ||
pub struct Mixin { | ||
Derived | ||
Struct | ||
field3 Iface = Iface(1) | ||
field4 ?Iface | ||
} | ||
|
||
fn test_main() { | ||
mut arr := []&Iface{} | ||
arr << &Derived{} | ||
arr << &Derived{} | ||
|
||
assert arr[0] == arr[1] | ||
|
||
s1 := Iface(Struct{}) | ||
s2 := Iface(Struct{}) | ||
assert s1 == s2 | ||
|
||
i1 := Iface(Mixin{}) | ||
i2 := Iface(Mixin{}) | ||
assert i1 == i2 | ||
} |