@@ -64,10 +64,12 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
64
64
}
65
65
66
66
fn (mut g Gen) index_range_expr (node ast.IndexExpr, range ast.RangeExpr) {
67
- sym := g.table.final_sym (g.unwrap_generic (node.left_type))
67
+ unwrapped_left_type := g.unwrap_generic (node.left_type)
68
+ sym := g.table.final_sym (unwrapped_left_type)
68
69
mut tmp_opt := ''
69
70
mut cur_line := ''
70
71
mut gen_or := node.or_expr.kind != .absent || node.is_option
72
+ left_is_shared := unwrapped_left_type.has_flag (.shared_f)
71
73
if sym.kind == .string {
72
74
if node.is_gated {
73
75
g.write ('string_substr_ni(' )
@@ -92,10 +94,16 @@ fn (mut g Gen) index_range_expr(node ast.IndexExpr, range ast.RangeExpr) {
92
94
} else {
93
95
g.write ('array_slice(' )
94
96
}
97
+ if left_is_shared {
98
+ g.write ('(' )
99
+ }
95
100
if node.left_type.is_ptr () {
96
101
g.write ('*' )
97
102
}
98
103
g.expr (node.left)
104
+ if left_is_shared {
105
+ g.write (').val' )
106
+ }
99
107
} else if sym.info is ast.ArrayFixed {
100
108
// Convert a fixed array to V array when doing `fixed_arr[start..end]`
101
109
noscan := g.check_noscan (sym.info.elem_type)
@@ -107,6 +115,9 @@ fn (mut g Gen) index_range_expr(node ast.IndexExpr, range ast.RangeExpr) {
107
115
g.write ('new_array_from_c_array${noscan} (' )
108
116
ctype := g.styp (sym.info.elem_type)
109
117
g.write ('${sym.info.size} , ${sym.info.size} , sizeof(${ctype} ), ' )
118
+ if left_is_shared {
119
+ g.write ('(' )
120
+ }
110
121
if node.left_type.is_ptr () {
111
122
g.write ('*' )
112
123
}
@@ -118,11 +129,14 @@ fn (mut g Gen) index_range_expr(node ast.IndexExpr, range ast.RangeExpr) {
118
129
g.write ('${styp} ${var} = ' )
119
130
g.expr (node.left)
120
131
g.writeln (';' )
121
- g.write2 (line, ' ${var} ) ' )
132
+ g.write2 (line, ' ${var} ' )
122
133
} else {
123
134
g.expr (node.left)
124
- g.write (')' )
125
135
}
136
+ if left_is_shared {
137
+ g.write (').val' )
138
+ }
139
+ g.write (')' )
126
140
} else {
127
141
g.expr (node.left)
128
142
}
@@ -192,7 +206,7 @@ fn (mut g Gen) index_of_array(node ast.IndexExpr, sym ast.TypeSymbol) {
192
206
}
193
207
194
208
if left_is_shared {
195
- if left_is_ptr {
209
+ if node.index ! is ast.RangeExpr && left_is_ptr {
196
210
g.write ('->val' )
197
211
} else {
198
212
g.write ('.val' )
0 commit comments