mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
This commit is contained in:
parent
136193a3aa
commit
51aaf3c49f
@ -9,7 +9,7 @@ struct PostTag {
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
new_post_tag := PostTag{}
|
||||
new_post_tag := &PostTag{}
|
||||
assert json.encode(new_post_tag) == '{"id":"","visibility":"","createdAt":"","metadata":""}'
|
||||
|
||||
new_post_tag2 := PostTag{
|
||||
|
@ -704,8 +704,9 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
||||
c.error('reference field must be initialized with reference',
|
||||
init_field.pos)
|
||||
}
|
||||
} else if exp_type.is_pointer() && !got_type.is_any_kind_of_pointer()
|
||||
&& !got_type.is_int() {
|
||||
} else if exp_type.is_any_kind_of_pointer()
|
||||
&& !got_type.is_any_kind_of_pointer() && !got_type.is_int()
|
||||
&& (!exp_type.has_flag(.option) || got_type.idx() != ast.none_type_idx) {
|
||||
got_typ_str := c.table.type_to_str(got_type)
|
||||
exp_typ_str := c.table.type_to_str(exp_type)
|
||||
c.error('cannot assign to field `${field_info.name}`: expected a pointer `${exp_typ_str}`, but got `${got_typ_str}`',
|
||||
|
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/struct_field_init_option_ref_err.vv:12:3: error: cannot assign to field `field`: expected a pointer `?&Foo`, but got `?Foo`
|
||||
10 | foo := ?Foo{}
|
||||
11 | _ := Bar{
|
||||
12 | field: foo
|
||||
| ~~~~~~~~~~
|
||||
13 | }
|
||||
14 | }
|
14
vlib/v/checker/tests/struct_field_init_option_ref_err.vv
Normal file
14
vlib/v/checker/tests/struct_field_init_option_ref_err.vv
Normal file
@ -0,0 +1,14 @@
|
||||
module main
|
||||
|
||||
struct Foo {}
|
||||
|
||||
struct Bar {
|
||||
field ?&Foo
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo := ?Foo{}
|
||||
_ := Bar{
|
||||
field: foo
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user