File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -804,7 +804,7 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
804
804
unwrapped_typ = unaliased_type.clear_flags (.option, .result)
805
805
}
806
806
}
807
- unwrapped_styp := g.typ (unwrapped_typ)
807
+ mut unwrapped_styp := g.typ (unwrapped_typ)
808
808
if g.infix_left_var_name.len > 0 {
809
809
g.indent--
810
810
g.writeln ('}' )
@@ -814,6 +814,11 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
814
814
g.write ('\n ${cur_line} ' )
815
815
} else if ! g.inside_curry_call {
816
816
if ! g.inside_const_opt_or_res {
817
+ if g.assign_ct_type != 0
818
+ && node.or_block.kind in [.propagate_option, .propagate_result] {
819
+ unwrapped_styp = g.typ (g.assign_ct_type.derive (node.return_type).clear_flags (.option,
820
+ .result))
821
+ }
817
822
g.write ('\n ${cur_line} (*(${unwrapped_styp} *)${tmp_opt} .data)' )
818
823
} else {
819
824
g.write ('\n ${cur_line} ${tmp_opt} ' )
Original file line number Diff line number Diff line change
1
+ struct Parent {
2
+ pub mut :
3
+ id int
4
+ name string
5
+ child Child
6
+ other Other
7
+ }
8
+
9
+ struct Child {
10
+ pub mut :
11
+ id int
12
+ age int
13
+ }
14
+
15
+ struct Other {
16
+ pub mut :
17
+ id int
18
+ name string
19
+ }
20
+
21
+ interface IdInterface {
22
+ mut :
23
+ id int
24
+ }
25
+
26
+ fn insert_ids [T](val T) ! T {
27
+ mut clone := val
28
+
29
+ $for field in T.fields {
30
+ $if field.typ is $struct {
31
+ clone.$(field.name) = insert_ids (val.$(field.name))!
32
+ }
33
+ }
34
+ $if T is IdInterface {
35
+ clone.id = 1
36
+ } $else {
37
+ return error ('${T.name} does not have an id field!' )
38
+ }
39
+ return clone
40
+ }
41
+
42
+ fn test_main () {
43
+ inserted := insert_ids (Parent{
44
+ name: 'test'
45
+ })!
46
+ assert inserted.child.id == 1
47
+ assert inserted.other.id == 1
48
+ }
You can’t perform that action at this time.
0 commit comments