mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: adjust fix for struct anon assigning to typed struct (#18264)
This commit is contained in:
parent
e8289dd4d5
commit
8a856cc36d
@ -698,7 +698,8 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if left_sym.kind == .struct_ && right is ast.StructInit && (right as ast.StructInit).is_anon {
|
||||
if left_sym.kind == .struct_ && !(left_sym.info as ast.Struct).is_anon
|
||||
&& right is ast.StructInit && (right as ast.StructInit).is_anon {
|
||||
c.error('cannot assign anonymous `struct` to a typed `struct`', right.pos())
|
||||
}
|
||||
}
|
||||
|
14
vlib/v/tests/anon_struct_assign_test.v
Normal file
14
vlib/v/tests/anon_struct_assign_test.v
Normal file
@ -0,0 +1,14 @@
|
||||
struct Parent {
|
||||
mut:
|
||||
val string
|
||||
child struct {
|
||||
mut:
|
||||
val string
|
||||
}
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut p := Parent{}
|
||||
p.child = struct {'abc'}
|
||||
assert p.child == struct {'abc'}
|
||||
}
|
Loading…
Reference in New Issue
Block a user