diff --git a/vlib/v/checker/tests/assign_sumtype2_err.out b/vlib/v/checker/tests/assign_sumtype2_err.out new file mode 100644 index 0000000000..9e1b60a1e0 --- /dev/null +++ b/vlib/v/checker/tests/assign_sumtype2_err.out @@ -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 | } diff --git a/vlib/v/checker/tests/assign_sumtype2_err.vv b/vlib/v/checker/tests/assign_sumtype2_err.vv new file mode 100644 index 0000000000..29e36cee3e --- /dev/null +++ b/vlib/v/checker/tests/assign_sumtype2_err.vv @@ -0,0 +1,15 @@ +type Stmt = Decl | Expr + +struct Decl {} +struct Expr {} + +struct File { + decl Decl +} + +fn main() { + stmt := Stmt(Decl{}) + _ := File{ + decl: stmt + } +} \ No newline at end of file diff --git a/vlib/v/checker/tests/assign_sumtype_err.out b/vlib/v/checker/tests/assign_sumtype_err.out new file mode 100644 index 0000000000..4df3d61b16 --- /dev/null +++ b/vlib/v/checker/tests/assign_sumtype_err.out @@ -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 | } diff --git a/vlib/v/checker/tests/assign_sumtype_err.vv b/vlib/v/checker/tests/assign_sumtype_err.vv new file mode 100644 index 0000000000..1225f833d7 --- /dev/null +++ b/vlib/v/checker/tests/assign_sumtype_err.vv @@ -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 +} \ No newline at end of file