aboutsummaryrefslogtreecommitdiff
path: root/tests/typeerrors
diff options
context:
space:
mode:
Diffstat (limited to 'tests/typeerrors')
-rw-r--r--tests/typeerrors/arg.zc5
-rw-r--r--tests/typeerrors/arith.zc3
-rw-r--r--tests/typeerrors/assign.zc3
-rw-r--r--tests/typeerrors/call.zc3
-rw-r--r--tests/typeerrors/deref.zc3
-rw-r--r--tests/typeerrors/enum_int.zc4
-rw-r--r--tests/typeerrors/enum_other.zc5
-rw-r--r--tests/typeerrors/field.zc3
-rw-r--r--tests/typeerrors/generic.zc4
-rw-r--r--tests/typeerrors/notstruct.zc2
-rw-r--r--tests/typeerrors/ret.zc4
-rw-r--r--tests/typeerrors/voidret.zc4
12 files changed, 43 insertions, 0 deletions
diff --git a/tests/typeerrors/arg.zc b/tests/typeerrors/arg.zc
new file mode 100644
index 0000000..bf39e85
--- /dev/null
+++ b/tests/typeerrors/arg.zc
@@ -0,0 +1,5 @@
+// expect: type error: argument: expected point*, got int*
+typecheck on;
+struct point { int x, y; };
+int f(point* p) { return p.x; }
+fn main() { int* q = new(int); f(q); free(d*q); return 0; }
diff --git a/tests/typeerrors/arith.zc b/tests/typeerrors/arith.zc
new file mode 100644
index 0000000..eda4aec
--- /dev/null
+++ b/tests/typeerrors/arith.zc
@@ -0,0 +1,3 @@
+// expect: type error: arithmetic needs numbers, got int*
+typecheck on;
+fn main() { int* p = 0; int x = p * 2; return x; }
diff --git a/tests/typeerrors/assign.zc b/tests/typeerrors/assign.zc
new file mode 100644
index 0000000..b83e1a2
--- /dev/null
+++ b/tests/typeerrors/assign.zc
@@ -0,0 +1,3 @@
+// expect: type error: initializer: expected char*, got int
+typecheck on;
+fn main() { char* s = 5; return 0; }
diff --git a/tests/typeerrors/call.zc b/tests/typeerrors/call.zc
new file mode 100644
index 0000000..7b03dbf
--- /dev/null
+++ b/tests/typeerrors/call.zc
@@ -0,0 +1,3 @@
+// expect: type error: only functions can be called, got int
+typecheck on;
+fn main() { int k = 3; return k(1); }
diff --git a/tests/typeerrors/deref.zc b/tests/typeerrors/deref.zc
new file mode 100644
index 0000000..ed030f5
--- /dev/null
+++ b/tests/typeerrors/deref.zc
@@ -0,0 +1,3 @@
+// expect: type error: only pointers can be dereferenced, got int
+typecheck on;
+fn main() { int x = 3; return *x; }
diff --git a/tests/typeerrors/enum_int.zc b/tests/typeerrors/enum_int.zc
new file mode 100644
index 0000000..c710d50
--- /dev/null
+++ b/tests/typeerrors/enum_int.zc
@@ -0,0 +1,4 @@
+// expect: type error: initializer: expected color, got int
+typecheck on;
+enum color { RED, GREEN = 5, BLUE };
+int main() { color c = 1; return c; }
diff --git a/tests/typeerrors/enum_other.zc b/tests/typeerrors/enum_other.zc
new file mode 100644
index 0000000..5b27370
--- /dev/null
+++ b/tests/typeerrors/enum_other.zc
@@ -0,0 +1,5 @@
+// expect: type error: initializer: expected color, got size
+typecheck on;
+enum color { RED, GREEN = 5, BLUE };
+enum size { SMALL, LARGE };
+int main() { color c = size.LARGE; return c; }
diff --git a/tests/typeerrors/field.zc b/tests/typeerrors/field.zc
new file mode 100644
index 0000000..ba03697
--- /dev/null
+++ b/tests/typeerrors/field.zc
@@ -0,0 +1,3 @@
+// expect: point has no field z
+struct point { int x, y; };
+fn main() { point p; return p.z; }
diff --git a/tests/typeerrors/generic.zc b/tests/typeerrors/generic.zc
new file mode 100644
index 0000000..04e5381
--- /dev/null
+++ b/tests/typeerrors/generic.zc
@@ -0,0 +1,4 @@
+// expect: type error: argument: expected int, got char*
+typecheck on;
+T same<T>(T a, T b) { return a; }
+fn main() { return same(1, "x"); }
diff --git a/tests/typeerrors/notstruct.zc b/tests/typeerrors/notstruct.zc
new file mode 100644
index 0000000..0dff6bd
--- /dev/null
+++ b/tests/typeerrors/notstruct.zc
@@ -0,0 +1,2 @@
+// expect: .x: that's a int, not a struct or a pointer to one
+fn main() { int n = 1; return n.x; }
diff --git a/tests/typeerrors/ret.zc b/tests/typeerrors/ret.zc
new file mode 100644
index 0000000..d44267e
--- /dev/null
+++ b/tests/typeerrors/ret.zc
@@ -0,0 +1,4 @@
+// expect: type error: return value: expected bool, got char*
+typecheck on;
+bool f() { return "no"; }
+fn main() { return f(); }
diff --git a/tests/typeerrors/voidret.zc b/tests/typeerrors/voidret.zc
new file mode 100644
index 0000000..86c9c17
--- /dev/null
+++ b/tests/typeerrors/voidret.zc
@@ -0,0 +1,4 @@
+// expect: type error: return value: expected void, got int
+typecheck on;
+void f() { return 3; }
+fn main() { f(); return 0; }