mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add missing check for mismatch anon struct to typed struct (#18250)
This commit is contained in:
parent
64a4a3316a
commit
9d56432e55
@ -698,6 +698,9 @@ 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 {
|
||||
c.error('cannot assign anonymous `struct` to a typed `struct`', right.pos())
|
||||
}
|
||||
}
|
||||
// this needs to run after the assign stmt left exprs have been run through checker
|
||||
// so that ident.obj is set
|
||||
|
7
vlib/v/checker/tests/anon_struct_assign_err.out
Normal file
7
vlib/v/checker/tests/anon_struct_assign_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/anon_struct_assign_err.vv:9:12: error: cannot assign anonymous `struct` to a typed `struct`
|
||||
7 | }
|
||||
8 | println(y)
|
||||
9 | y = struct {
|
||||
| ^
|
||||
10 | name: 'Def'
|
||||
11 | }
|
12
vlib/v/checker/tests/anon_struct_assign_err.vv
Normal file
12
vlib/v/checker/tests/anon_struct_assign_err.vv
Normal file
@ -0,0 +1,12 @@
|
||||
struct Abc {
|
||||
name string
|
||||
}
|
||||
|
||||
mut y := Abc{
|
||||
name: 'Abc'
|
||||
}
|
||||
println(y)
|
||||
y = struct {
|
||||
name: 'Def'
|
||||
}
|
||||
println(y)
|
Loading…
Reference in New Issue
Block a user