File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -200,8 +200,12 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
200200 }
201201 }
202202
203- value_type := c.table.value_type (unwrapped_typ)
203+ mut value_type := c.table.value_type (unwrapped_typ)
204+ if node.val_is_mut {
205+ value_type = value_type.ref ()
206+ }
204207 node.scope.update_var_type (node.val_var, value_type)
208+ node.val_type = value_type
205209
206210 if is_comptime {
207211 c.type_resolver.update_ct_type (node.val_var, value_type)
Original file line number Diff line number Diff line change @@ -154,6 +154,9 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
154154
155155 node.cond_type = unwrapped_typ
156156 node.val_type = g.table.value_type (unwrapped_typ)
157+ if node.val_is_mut {
158+ node.val_type = node.val_type.ref ()
159+ }
157160 node.scope.update_var_type (node.val_var, node.val_type)
158161 node.kind = unwrapped_sym.kind
159162
Original file line number Diff line number Diff line change 1+ struct ValueMenu {
2+ name string
3+ }
4+
5+ fn (mut v ValueMenu) resp (resp []u8 ) {
6+ println ('menu ${v .name } ${resp }' )
7+ }
8+
9+ fn value_resp [T](mut t T, r []u8 ) {
10+ $if T is $array {
11+ value_array_resp (mut t, r)
12+ }
13+ }
14+
15+ fn value_array_resp [T](mut t T, r []u8 ) {
16+ $if T is []ValueMenu {
17+ for _, mut i in t { // mut i -> C error
18+ i.resp (r)
19+ }
20+ for i := 0 ; i < t.len; i++ { // WORKAROUND
21+ t[i].resp (r)
22+ }
23+ }
24+ }
25+
26+ struct Colors {
27+ mut :
28+ normal []ValueMenu = [ValueMenu{'blink' }, ValueMenu{'hue' }]
29+ }
30+
31+ fn (c &Colors) resp (resp []u8 ) {
32+ $for f in c.fields {
33+ mut m := c.$(f.name)
34+ value_resp (mut m, resp)
35+ }
36+ }
37+
38+ fn test_main () {
39+ colors := & Colors{}
40+ colors.resp ([u8 (0 ), 1 , 2 ])
41+ assert true
42+ }
You can’t perform that action at this time.
0 commit comments