mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
parent
6b31c86fea
commit
9ae8cc357f
2 changed files with 41 additions and 2 deletions
|
@ -713,8 +713,7 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
|
||||||
if got_type.has_flag(.result) {
|
if got_type.has_flag(.result) {
|
||||||
c.check_expr_option_or_result_call(init_field.expr, init_field.typ)
|
c.check_expr_option_or_result_call(init_field.expr, init_field.typ)
|
||||||
}
|
}
|
||||||
if exp_type_is_option && got_type.is_ptr() && !(exp_type.is_ptr()
|
if exp_type_is_option && got_type.is_ptr() && !exp_type.is_ptr() {
|
||||||
&& exp_type_sym.kind == .struct) {
|
|
||||||
c.error('cannot assign a pointer to option struct field', init_field.pos)
|
c.error('cannot assign a pointer to option struct field', init_field.pos)
|
||||||
}
|
}
|
||||||
if exp_type_sym.kind == .voidptr && got_type_sym.kind == .struct
|
if exp_type_sym.kind == .voidptr && got_type_sym.kind == .struct
|
||||||
|
|
40
vlib/v/tests/options/option_ptr_field_test.v
Normal file
40
vlib/v/tests/options/option_ptr_field_test.v
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
module main
|
||||||
|
|
||||||
|
@[heap]
|
||||||
|
interface IGameObject {
|
||||||
|
mut:
|
||||||
|
name string
|
||||||
|
parent ?&IGameObject
|
||||||
|
}
|
||||||
|
|
||||||
|
@[heap]
|
||||||
|
struct GameObject implements IGameObject {
|
||||||
|
mut:
|
||||||
|
name string
|
||||||
|
parent ?&IGameObject
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Ship implements IGameObject {
|
||||||
|
GameObject
|
||||||
|
speed f32
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
mut world := &GameObject{
|
||||||
|
name: 'world'
|
||||||
|
}
|
||||||
|
mut ship := &Ship{
|
||||||
|
name: 'ship'
|
||||||
|
parent: world
|
||||||
|
}
|
||||||
|
assert '${ship}' == "&Ship{
|
||||||
|
GameObject: GameObject{
|
||||||
|
name: 'ship'
|
||||||
|
parent: &Option(IGameObject(GameObject{
|
||||||
|
name: 'world'
|
||||||
|
parent: &Option(none)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
speed: 0.0
|
||||||
|
}"
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue