1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add tests for assign sum type to non sum type error

This commit is contained in:
joe-conigliaro 2020-12-11 21:52:25 +11:00
parent 5c213de003
commit 90b5f6f4e0
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1
4 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/assign_sumtype2_err.vv:13:3: error: cannot assign to field `decl`: expected `Decl`, not `Stmt`
11 | stmt := Stmt(Decl{})
12 | _ := File{
13 | decl: stmt
| ~~~~~~~~~~
14 | }
15 | }

View File

@ -0,0 +1,15 @@
type Stmt = Decl | Expr
struct Decl {}
struct Expr {}
struct File {
decl Decl
}
fn main() {
stmt := Stmt(Decl{})
_ := File{
decl: stmt
}
}

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/assign_sumtype_err.vv:13:9: error: cannot assign to `decl`: expected `Decl`, not `Stmt`
11 | stmt := Stmt(Decl{})
12 | mut decl := Decl{}
13 | decl = stmt
| ~~~~
14 | }

View File

@ -0,0 +1,14 @@
type Stmt = Decl | Expr
struct Decl {}
struct Expr {}
struct File {
decl Decl
}
fn main() {
stmt := Stmt(Decl{})
mut decl := Decl{}
decl = stmt
}