diff options
| author | 2026-10-12 08:46:23 +0330 | |
|---|---|---|
| committer | 2026-10-12 08:46:23 +0330 | |
| commit | ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch) | |
| tree | 70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/programs/typeok.zc | |
a
Diffstat (limited to 'tests/programs/typeok.zc')
| -rw-r--r-- | tests/programs/typeok.zc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/programs/typeok.zc b/tests/programs/typeok.zc new file mode 100644 index 0000000..26ab3ad --- /dev/null +++ b/tests/programs/typeok.zc @@ -0,0 +1,21 @@ +// passes the typechecker: words mix with everything, literal 0 is null, +// arrays decay to pointers, generic calls bind their parameters +typecheck on; +struct pair<A, B> { A a; B b; }; +pair<A, B>*.u mk<A, B>(A x, B y) { pair<A, B>* p = new(pair<A, B>); p.a = x; p.b = y; return u*p; } +A left<A, B>(pair<A, B>* p) { return p.a; } +int strlen2(char* s) { int n = 0; while (s[n]) n++; return n; } +int main() { + pair<int, char*>* p = mk(3, "four"); + int a = left(p); + char* s = p.b; + [8]char buf; + char* q = buf; + int* nothing = 0; + let w = 5; + int mixed = w + 1; + q[0] = 'h'; q[1] = 0; + put_n(a + strlen2(s) + strlen2(buf) + mixed); put_c(10); + free(d*p); + return 0; +} |
