aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 16:51:03 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 16:51:03 +0330
commit82f8b735f966be69f9892350fb0a719f3fc436f1 (patch)
tree5a6d7d3f226febfcbe5280f6da7796ef2ff2c6b2
parentlexer: a block comment that is never closed is 'unterminated comment' (append... (diff)
as: the type after as is read greedily in both compilers; x as int * y is a syntax error (appendix b.2.12 settled, no compiler change)
-rw-r--r--docs/SPEC.md4
-rw-r--r--tests/conformance/3-expressions/cast_as_then_multiply_parenthesised.zc5
-rw-r--r--tests/conformance/9-appendix-b/b2_12_as_int_star.zc6
-rw-r--r--tests/conformance/known.txt1
4 files changed, 10 insertions, 6 deletions
diff --git a/docs/SPEC.md b/docs/SPEC.md
index cc94451..30d547d 100644
--- a/docs/SPEC.md
+++ b/docs/SPEC.md
@@ -361,7 +361,7 @@ a = b = 7 // assigns both, value 7
```
`&&` and `||` are lower than `|`. this matches c.
-3.2.3 `as` is a postfix operator: it applies to the operand to its left and binds tighter than every binary operator, so `a + b as T` is `a + (b as T)`. a type after `as` takes following stars: `x as int * y` parses `int*` then fails. parenthesise.
+3.2.3 `as` is a postfix operator: it applies to the operand to its left and binds tighter than every binary operator, so `a + b as T` is `a + (b as T)`. the type after `as` is read greedily, stars included (`x as char**`), in both compilers: `x as int * y` reads `int*` and then is a syntax error; write `(x as int) * y`.
3.2.4 the condition of `?:` is a `binary` expression (so `a = b ? c : d` is `a = (b ? c : d)`), the middle operand and the last operand are full `expr` (assignments allowed). `a ? b : c = 5` therefore parses as `a ? b : (c = 5)`: with `a` 1 the assignment does not run.
@@ -1115,7 +1115,7 @@ each item gives a minimal program, the expected behavior (per this spec) and the
9. fixed (5.12.7): `include std;` inside a function body gave `return outside a function`; it is now error: include is top level only.
10. a syntax error hides errors in the statements skipped by recovery: `int a = ; int b = 3 +;` reports only the first error (8.2). by design, but easy to miss.
11. fixed (1.2.2): an unterminated `/* ...` comment was accepted silently; it is error: unterminated comment. (an unterminated string literal is still only reported as a later syntax error.)
-12. `x as int * y` parses `int*` as the type (3.2.3).
+12. settled (3.2.3): `x as int * y` parses `int*` as the type. this is the rule (the type is read greedily, as zc0 does too), so the program is a syntax error.
13. prototypes need parameter names: `int f(int);` => `expected a name, found ')'`.
14. `len(s)` on a `char*` returns word 0 of the string when `typecheck` is off.
15. duplicate `case` labels are not diagnosed (4.7.2).
diff --git a/tests/conformance/3-expressions/cast_as_then_multiply_parenthesised.zc b/tests/conformance/3-expressions/cast_as_then_multiply_parenthesised.zc
new file mode 100644
index 0000000..ab11217
--- /dev/null
+++ b/tests/conformance/3-expressions/cast_as_then_multiply_parenthesised.zc
@@ -0,0 +1,5 @@
+// expect: 6/
+// spec 3.2.3: (x as int) * y multiplies
+include rt;
+void pn(int x) { rt.put_n(x); rt.put_c(10); }
+fn main() { int x = 2; int y = 3; pn((x as int) * y); return 0; }
diff --git a/tests/conformance/9-appendix-b/b2_12_as_int_star.zc b/tests/conformance/9-appendix-b/b2_12_as_int_star.zc
index fc12792..da54802 100644
--- a/tests/conformance/9-appendix-b/b2_12_as_int_star.zc
+++ b/tests/conformance/9-appendix-b/b2_12_as_int_star.zc
@@ -1,6 +1,6 @@
-// expect: 6/
-// spec appendix b.2.12: x as int * y should multiply
+// expect error: expected ')', found 'y'
+// spec 3.2.3 and appendix b.2.12: the type after as is read greedily, so x as int * y reads int* and then fails; write (x as int) * y
include rt;
void pn(int x) { rt.put_n(x); rt.put_c(10); }
fn main() { int x = 2; int y = 3; pn(x as int * y); return 0; }
-// zc0: skip
+// zc0: error
diff --git a/tests/conformance/known.txt b/tests/conformance/known.txt
index f666106..7cb703e 100644
--- a/tests/conformance/known.txt
+++ b/tests/conformance/known.txt
@@ -4,7 +4,6 @@
4-statements/o3_outside_function_ordinary_block.zc zy c top-level o3 { } is rejected; spec 4.10.2 says it is an ordinary block
5-declarations/fn_prototype_unnamed_params_b13.zc zy c spec 5.2.1 says prototype parameter names are required, and a type name alone is read as an untyped parameter of that name (paramstart); b.2.13 is a spec choice, not fixed
9-appendix-b/b2_10_recovery_hides_errors.zc zy c appendix b.2.10 confirmed; by design per 8.2
-9-appendix-b/b2_12_as_int_star.zc zy c appendix b.2.12 confirmed, but spec 3.2.3 documents it (parenthesise)
9-appendix-b/b2_14_len_char_ptr_typecheck_off.zc zy c appendix b.2.14 confirmed, but spec 3.13.5 leaves it unspecified
9-appendix-b/b2_15_duplicate_case.zc zy c appendix b.2.15 confirmed; 4.7.2 says duplicates are allowed
9-appendix-b/b2_16_local_const_in_const_expr.zc zy c appendix b.2.16 confirmed; 3.14.2 documents it