mirror of
https://github.com/vlang/v.git
synced 2025-09-15 02:18:47 -04:00
parent
09fff08611
commit
2d314fc9b0
@ -4278,7 +4278,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
|
||||
}
|
||||
alias_to_ptr := sym.info is ast.Alias && sym.info.parent_type.is_ptr()
|
||||
if field_is_opt
|
||||
|| ((node.expr_type.is_ptr() || sym.kind == .chan || alias_to_ptr)
|
||||
|| ((g.unwrap_generic(node.expr_type).is_ptr() || sym.kind == .chan || alias_to_ptr)
|
||||
&& node.from_embed_types.len == 0)
|
||||
|| (node.expr.is_as_cast() && g.inside_smartcast) {
|
||||
g.write('->')
|
||||
|
19
vlib/v/tests/generic_selector_ptr_test.v
Normal file
19
vlib/v/tests/generic_selector_ptr_test.v
Normal file
@ -0,0 +1,19 @@
|
||||
module main
|
||||
|
||||
struct Foo123 {
|
||||
field string = 'foobar'
|
||||
}
|
||||
|
||||
fn gen_func[T](value T) string {
|
||||
$if T is i32 {
|
||||
return '123'
|
||||
} $else $if T is &Foo123 {
|
||||
return value.field
|
||||
} $else {
|
||||
return '123'
|
||||
}
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
assert gen_func[&Foo123](&Foo123{}) == 'foobar'
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user