File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -188,7 +188,13 @@ fn (mut g Gen) gen_struct_equality_fn(left_type ast.Type) string {
188188
189189 // overloaded
190190 if left.sym.has_method ('==' ) {
191- fn_builder.writeln ('\t return ${fn_name} __eq(a, b);' )
191+ if left.typ.has_flag (.option) {
192+ opt_ptr_styp := g.typ (left.typ.set_nr_muls (0 ).clear_flag (.option))
193+ opt_fn_name := opt_ptr_styp.replace ('struct ' , '' )
194+ fn_builder.writeln ('\t return (a.state == b.state && b.state == 2) || ${opt_fn_name} __eq(*(${opt_ptr_styp} *)a.data, *(${opt_ptr_styp} *)b.data);' )
195+ } else {
196+ fn_builder.writeln ('\t return ${fn_name} __eq(a, b);' )
197+ }
192198 fn_builder.writeln ('}' )
193199 return fn_name
194200 }
Original file line number Diff line number Diff line change 1+ import time
2+
3+ struct SubTestTimeOptional [T] {
4+ iis string
5+ ext T
6+ }
7+
8+ pub fn (s1 SubTestTimeOptional[T]) == (s2 SubTestTimeOptional[T]) bool {
9+ return s1 .iis == s2 .iis
10+ }
11+
12+ struct TestTimeOptional {
13+ exp ? time.Time
14+ }
15+
16+ fn now_optional [T]() SubTestTimeOptional[T] {
17+ return SubTestTimeOptional[TestTimeOptional]{
18+ iis: 'Vtest'
19+ ext: TestTimeOptional{
20+ exp: time.now ()
21+ }
22+ }
23+ }
24+
25+ fn now_delay_optional [T]() SubTestTimeOptional[T] {
26+ return SubTestTimeOptional[T]{
27+ iis: 'Vtest'
28+ ext: TestTimeOptional{
29+ exp: time.now ().add_seconds (5 )
30+ }
31+ }
32+ }
33+
34+ fn test_main () {
35+ mut t1 := now_optional[TestTimeOptional]()
36+ mut t2 := now_delay_optional[TestTimeOptional]()
37+ assert t1 != t2
38+ }
You can’t perform that action at this time.
0 commit comments