mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix selector accessing field (#17567)
This commit is contained in:
parent
737e7f6410
commit
d353dd6e8a
@ -3461,7 +3461,12 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
|
||||
g.write('*(')
|
||||
}
|
||||
g.expr(node.expr)
|
||||
g.write('.${field_name}')
|
||||
if node.expr_type.is_ptr() {
|
||||
g.write('->')
|
||||
} else {
|
||||
g.write('.')
|
||||
}
|
||||
g.write(field_name)
|
||||
if is_ptr {
|
||||
g.write(')')
|
||||
}
|
||||
|
27
vlib/v/tests/option_selector_test.v
Normal file
27
vlib/v/tests/option_selector_test.v
Normal file
@ -0,0 +1,27 @@
|
||||
module main
|
||||
|
||||
struct JsonParser {
|
||||
mut:
|
||||
js string
|
||||
tokens []string
|
||||
pos int
|
||||
tok_next int
|
||||
tok_super ?int
|
||||
}
|
||||
|
||||
fn new_parser(qty int) JsonParser {
|
||||
return JsonParser{
|
||||
tokens: []string{cap: qty}
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut p JsonParser) parse() int {
|
||||
j := p.tok_super or { 999 }
|
||||
return j
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut x := new_parser(100)
|
||||
i := x.parse()
|
||||
assert i == 999
|
||||
}
|
Loading…
Reference in New Issue
Block a user