From 79de454a7df8bd2862d32835db89ed06de8e7b33 Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 16:15:52 +0330 Subject: zc0: x as T reads a whole type (x as int*, x as char**) --- src/tools/zc0.c | 2 +- tests/conformance/3-expressions/cast_as_pointer_type.zc | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/conformance/3-expressions/cast_as_pointer_type.zc diff --git a/src/tools/zc0.c b/src/tools/zc0.c index 20dcbf9..f28c655 100644 --- a/src/tools/zc0.c +++ b/src/tools/zc0.c @@ -637,7 +637,7 @@ static void postfix(void) else if (is("(")) { rval(); n = args(); lit(n); op(O_PICK); op(O_CALL); op(O_SWAP); op(O_DROP); xf = 0; xs = 0; lvi = -1; } else if (accept("++")) incdec(1, 1); else if (accept("--")) incdec(1, -1); - else if (accept("as")) ident(); + else if (accept("as")) ptype0(); /* the whole type, as the compiler reads it: x as int*, x as char** */ else return; } } diff --git a/tests/conformance/3-expressions/cast_as_pointer_type.zc b/tests/conformance/3-expressions/cast_as_pointer_type.zc new file mode 100644 index 0000000..5ebc696 --- /dev/null +++ b/tests/conformance/3-expressions/cast_as_pointer_type.zc @@ -0,0 +1,15 @@ +// expect: 4/5/1/ +// spec: the type after `as` is a whole type, stars included (zc0 used to read one name) +include rt; +void pn(int x) { rt.put_n(x); rt.put_c(10); } +int[3] a; +fn main() { + a[1] = 4; a[2] = 5; + word w = a; + int* q = w as int*; + char** r = 0 as char**; + pn((q as int*)[1]); + pn(q[2]); + pn(r == 0); + return 0; +} -- cgit v1.2.3