From 90b5f6f4e0c292154670356878e3a6d3f97d40a9 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Fri, 11 Dec 2020 21:52:25 +1100 Subject: [PATCH] checker: add tests for assign sum type to non sum type error --- vlib/v/checker/tests/assign_sumtype2_err.out | 7 +++++++ vlib/v/checker/tests/assign_sumtype2_err.vv | 15 +++++++++++++++ vlib/v/checker/tests/assign_sumtype_err.out | 6 ++++++ vlib/v/checker/tests/assign_sumtype_err.vv | 14 ++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 vlib/v/checker/tests/assign_sumtype2_err.out create mode 100644 vlib/v/checker/tests/assign_sumtype2_err.vv create mode 100644 vlib/v/checker/tests/assign_sumtype_err.out create mode 100644 vlib/v/checker/tests/assign_sumtype_err.vv 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