Skip to content

Commit 4686c89

Browse files
committed
fix
1 parent a75af23 commit 4686c89

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

vlib/v/gen/c/assign.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn (mut g Gen) expr_with_opt(expr ast.Expr, expr_typ ast.Type, ret_typ ast.Type)
163163
}
164164
g.expr(expr)
165165
if expr is ast.ComptimeSelector {
166-
return '${expr.left.str()}.${g.comptime.comptime_for_field_value.name}'
166+
return g.comptime_selector_str(expr)
167167
} else {
168168
return expr.str()
169169
}

vlib/v/gen/c/cgen.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -3728,7 +3728,7 @@ fn (mut g Gen) expr(node_ ast.Expr) {
37283728
mut is_unwrapped := true
37293729
if mut node.expr is ast.ComptimeSelector && node.expr.left is ast.Ident {
37303730
// val.$(field.name)?
3731-
expr_str = '${node.expr.left.str()}.${g.comptime.comptime_for_field_value.name}'
3731+
expr_str = g.comptime_selector_str(node.expr)
37323732
} else if mut node.expr is ast.Ident && node.expr.ct_expr {
37333733
// val?
37343734
expr_str = node.expr.name

vlib/v/gen/c/comptime.v

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ fn (mut g Gen) comptime_selector(node ast.ComptimeSelector) {
3939
}
4040
}
4141

42+
fn (mut g Gen) comptime_selector_str(expr ast.ComptimeSelector) string {
43+
arrow_or_dot := if expr.left_type.is_ptr() { '->' } else { '.' }
44+
return '${expr.left.str()}${arrow_or_dot}${g.comptime.comptime_for_field_value.name}'
45+
}
46+
4247
fn (mut g Gen) comptime_call(mut node ast.ComptimeCall) {
4348
if node.is_embed {
4449
// $embed_file('/path/to/file')

vlib/v/tests/options/option_var_test.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mut:
2222

2323
struct Decoder {}
2424

25-
fn (d &Decoder) decode[T](typ T) T {
25+
fn (d &Decoder) decode[T](mut typ T) T {
2626
$for field in T.fields {
2727
$if field.is_option {
2828
if typ.$(field.name) != none {
@@ -36,7 +36,7 @@ fn (d &Decoder) decode[T](typ T) T {
3636

3737
fn test_comptime() {
3838
d := Decoder{}
39-
result := d.decode(StructType{
39+
result := d.decode(mut StructType{
4040
a: 'foo'
4141
b: 3
4242
})

0 commit comments

Comments
 (0)