Skip to content

Commit 6cb75b2

Browse files
committed
Add more complex tests
1 parent cd470ba commit 6cb75b2

File tree

3 files changed

+138
-2
lines changed

3 files changed

+138
-2
lines changed

compiler-core/src/type_/tests/errors.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,10 @@ fn module_could_not_unify6() {
744744
}
745745

746746
#[test]
747-
fn module_could_not_unify_let_binding_annotation_follow_up() {
747+
fn module_could_not_unify_let_binding_annotation_follow_up1() {
748748
assert_module_error!(
749749
"
750-
pub fn main() {
750+
fn main() {
751751
let x: String = 5
752752
let y: Int = x
753753
let z: String = x
@@ -756,6 +756,24 @@ pub fn main() {
756756
);
757757
}
758758

759+
#[test]
760+
fn module_could_not_unify_let_binding_annotation_follow_up2() {
761+
assert_module_error!(
762+
"
763+
fn main() {
764+
let #(
765+
a,
766+
[[_, ..] as b, ..],
767+
_ as c
768+
): #(String, List(Int), String) = #(1, [\"Hello\"], 3)
769+
770+
let d: String = a <> c
771+
let e: List(Int) = [\"Hello\", ..b]
772+
}
773+
"
774+
);
775+
}
776+
759777
#[test]
760778
fn module_could_not_unify7() {
761779
assert_module_error!("fn main() { let assert 5 = \"\" }");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nfn main() {\n let x: String = 5\n let y: Int = x\n let z: String = x\n}\n"
4+
---
5+
----- SOURCE CODE
6+
7+
fn main() {
8+
let x: String = 5
9+
let y: Int = x
10+
let z: String = x
11+
}
12+
13+
14+
----- ERROR
15+
error: Type mismatch
16+
┌─ /src/one/two.gleam:3:19
17+
18+
3let x: String = 5
19+
^
20+
21+
Expected type:
22+
23+
String
24+
25+
Found type:
26+
27+
Int
28+
29+
error: Type mismatch
30+
┌─ /src/one/two.gleam:4:16
31+
32+
4let y: Int = x
33+
^
34+
35+
Expected type:
36+
37+
Int
38+
39+
Found type:
40+
41+
String
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\nfn main() {\n let #(\n a, \n [[_, ..] as b, ..], \n _ as c\n ): #(String, List(Int), String) = #(1, [\"Hello\"], 3)\n\n let d: String = a <> c\n let e: List(Int) = [\"Hello\", ..b]\n}\n"
4+
---
5+
----- SOURCE CODE
6+
7+
fn main() {
8+
let #(
9+
a,
10+
[[_, ..] as b, ..],
11+
_ as c
12+
): #(String, List(Int), String) = #(1, ["Hello"], 3)
13+
14+
let d: String = a <> c
15+
let e: List(Int) = ["Hello", ..b]
16+
}
17+
18+
19+
----- ERROR
20+
error: Type mismatch
21+
┌─ /src/one/two.gleam:5:10
22+
23+
5 │ [[_, ..] as b, ..],
24+
^^^^^^^
25+
26+
Expected type:
27+
28+
String
29+
30+
Found type:
31+
32+
List(a)
33+
34+
error: Type mismatch
35+
┌─ /src/one/two.gleam:7:39
36+
37+
7 │ ): #(String, List(Int), String) = #(1, ["Hello"], 3)
38+
^^^^^^^^^^^^^^^^^^
39+
40+
Expected type:
41+
42+
#(String, List(Int), String)
43+
44+
Found type:
45+
46+
#(Int, List(String), Int)
47+
48+
error: Type mismatch
49+
┌─ /src/one/two.gleam:10:24
50+
51+
10let e: List(Int) = ["Hello", ..b]
52+
^^^^^^^^^^^^^^
53+
54+
Expected type:
55+
56+
List(Int)
57+
58+
Found type:
59+
60+
List(String)
61+
62+
error: Type mismatch
63+
┌─ /src/one/two.gleam:10:36
64+
65+
10let e: List(Int) = ["Hello", ..b]
66+
^
67+
68+
All elements in a list must have the same type, but the elements of
69+
this list don't match the type of the elements being prepended to it.
70+
71+
Expected type:
72+
73+
List(String)
74+
75+
Found type:
76+
77+
Int

0 commit comments

Comments
 (0)