1
0
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:
Felipe Pena 2023-05-25 14:40:20 -03:00 committed by GitHub
parent e8289dd4d5
commit 8a856cc36d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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())
}
}

View 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'}
}