mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
5006ffb304
commit
76ae9dba5c
@ -544,6 +544,12 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
|
||||
&& field.expr.str() != '0' && !exp_type.has_flag(.option) {
|
||||
c.error('reference field must be initialized with reference',
|
||||
field.pos)
|
||||
} else if exp_type.is_pointer() && !got_type.is_any_kind_of_pointer()
|
||||
&& !got_type.is_int() {
|
||||
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}`',
|
||||
field.pos)
|
||||
}
|
||||
}
|
||||
node.fields[i].typ = got_type
|
||||
|
7
vlib/v/checker/tests/struct_voidptr_field_init_err.out
Normal file
7
vlib/v/checker/tests/struct_voidptr_field_init_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/struct_voidptr_field_init_err.vv:7:3: error: cannot assign to field `example`: expected a pointer `voidptr`, but got `string`
|
||||
5 | fn main() {
|
||||
6 | println(Example{
|
||||
7 | example: get()
|
||||
| ~~~~~~~~~~~~~~
|
||||
8 | })
|
||||
9 | }
|
13
vlib/v/checker/tests/struct_voidptr_field_init_err.vv
Normal file
13
vlib/v/checker/tests/struct_voidptr_field_init_err.vv
Normal file
@ -0,0 +1,13 @@
|
||||
struct Example {
|
||||
example voidptr
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println(Example{
|
||||
example: get()
|
||||
})
|
||||
}
|
||||
|
||||
fn get() string {
|
||||
return 'hello'
|
||||
}
|
Loading…
Reference in New Issue
Block a user