From 6bb3d79cbd853601623095b497a1807489c3ef6e Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 09:39:22 +0000 Subject: add c-style typedef and a built-in string alias typedef T name; binds name to the type record of T, at the top level or in a function (scoped to its block). string is a built-in alias for char*. A type name straight before , or ) in a parameter list is the parameter's name, so fn f(string) still works. The language server shows typedef T name; on hover and highlights typedef as a keyword. --- tests/typeerrors/typedef_mismatch.zc | 6 ++++++ tests/typeerrors/typedef_pointer.zc | 7 +++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/typeerrors/typedef_mismatch.zc create mode 100644 tests/typeerrors/typedef_pointer.zc (limited to 'tests/typeerrors') diff --git a/tests/typeerrors/typedef_mismatch.zc b/tests/typeerrors/typedef_mismatch.zc new file mode 100644 index 0000000..26453dd --- /dev/null +++ b/tests/typeerrors/typedef_mismatch.zc @@ -0,0 +1,6 @@ +namespace; + +// expect: type error: initializer: expected int, got char* +typecheck on; +typedef int count; +fn main() { count c = "text"; return 0; } diff --git a/tests/typeerrors/typedef_pointer.zc b/tests/typeerrors/typedef_pointer.zc new file mode 100644 index 0000000..5dbbb17 --- /dev/null +++ b/tests/typeerrors/typedef_pointer.zc @@ -0,0 +1,7 @@ +namespace; + +// expect: type error: initializer: expected node*, got int* +typecheck on; +struct node { int v; }; +typedef node* link; +fn main() { int n = 0; link p = &n; return 0; } -- cgit v1.2.3