From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- tests/typeerrors/arg.zc | 5 +++++ tests/typeerrors/arith.zc | 3 +++ tests/typeerrors/assign.zc | 3 +++ tests/typeerrors/call.zc | 3 +++ tests/typeerrors/deref.zc | 3 +++ tests/typeerrors/enum_int.zc | 4 ++++ tests/typeerrors/enum_other.zc | 5 +++++ tests/typeerrors/field.zc | 3 +++ tests/typeerrors/generic.zc | 4 ++++ tests/typeerrors/notstruct.zc | 2 ++ tests/typeerrors/ret.zc | 4 ++++ tests/typeerrors/voidret.zc | 4 ++++ 12 files changed, 43 insertions(+) create mode 100644 tests/typeerrors/arg.zc create mode 100644 tests/typeerrors/arith.zc create mode 100644 tests/typeerrors/assign.zc create mode 100644 tests/typeerrors/call.zc create mode 100644 tests/typeerrors/deref.zc create mode 100644 tests/typeerrors/enum_int.zc create mode 100644 tests/typeerrors/enum_other.zc create mode 100644 tests/typeerrors/field.zc create mode 100644 tests/typeerrors/generic.zc create mode 100644 tests/typeerrors/notstruct.zc create mode 100644 tests/typeerrors/ret.zc create mode 100644 tests/typeerrors/voidret.zc (limited to 'tests/typeerrors') 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 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; } -- cgit v1.2.3