Skip to content

Commit 24bd52e

Browse files
committed
Raise Zig unsupported expression diagnostics
1 parent f9d8e48 commit 24bd52e

6 files changed

Lines changed: 20 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4444
- Local file-based imports now load dependencies during semantic analysis and fail closed on missing or broken modules.
4545
- Built-in stdlib imports such as `std/io` and `std/math` remain virtual so existing examples do not require on-disk stdlib `.a7` files.
4646

47+
- **Zig backend diagnostics**
48+
- Unsupported expression nodes now raise compiler-side `CodegenError` instead of emitting Zig `@compileError` fallback expressions.
49+
4750
- **Semantic and preprocessing correctness**
4851
- `defer` now traverses its parsed `statement` payload in both type checking and semantic validation.
4952
- `ret` semantic validation now traverses the parser's `value` payload.

MISSING_FEATURES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
15. Debug/release example artifact verification is available through `scripts/build_examples.py`.
3030
16. `run_all_tests.sh` includes C backend verification, both example E2E verifiers, debug/release artifact builds, the error-stage matrix, docs style checks, and full pytest.
3131
17. Local file-based imports now fail closed during semantic analysis instead of swallowing module loading failures.
32+
18. Zig unsupported expression fallbacks now fail as compiler-side codegen errors instead of generated `@compileError` expressions.
3233

3334
---
3435

RELEASE_READINESS_REVIEW.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ not factually provable from local tests alone.
6060

6161
## Recommended Next Pass
6262

63-
1. Replace Zig backend `@compileError("unsupported")` fallbacks with compiler
64-
codegen errors.
65-
2. Add tag-based release workflow after choosing the package publishing target.
66-
3. Add secret scanning to CI.
67-
4. Expand differential backend tests beyond examples.
68-
5. Unify virtual stdlib imports with file-based module semantics.
63+
1. Add tag-based release workflow after choosing the package publishing target.
64+
2. Add secret scanning to CI.
65+
3. Expand differential backend tests beyond examples.
66+
4. Unify virtual stdlib imports with file-based module semantics.
67+
5. Implement `fall` semantic validation and backend lowering.

TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ These are bugs and schema mismatches in already-implemented features.
2121
Files: `src/passes/semantic_validator.py`, `src/backends/zig.py`, `src/backends/c.py`
2222
Notes: `NodeKind.FALL` is parsed and documented, but semantic validation and backend lowering are still pending.
2323

24-
- [ ] Replace Zig backend `@compileError("unsupported: ...")` fallbacks with compiler-side codegen errors.
24+
- [x] Replace Zig backend `@compileError("unsupported: ...")` fallbacks with compiler-side codegen errors.
2525
Files: `src/backends/zig.py`
26-
Notes: unsupported AST nodes should fail during compilation, not after emitting Zig source.
26+
Notes: unsupported expression nodes now raise `CodegenError` during A7 compilation.
2727

2828
- [ ] Stop C slice/iteration lowering from re-evaluating side-effectful expressions.
2929
Files: `src/backends/c.py`

src/backends/zig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ def _emit_expr(self, node: ASTNode) -> str:
10151015
NodeKind.TYPE_GENERIC):
10161016
return self._emit_type_node(node)
10171017
else:
1018-
return f"@compileError(\"unsupported: {kind.name}\")"
1018+
raise CodegenError(f"Zig backend: unsupported expression node '{kind.name}'", node.span)
10191019

10201020
def _emit_literal(self, node: ASTNode) -> str:
10211021
"""Emit a literal value."""

test/test_codegen_zig.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
from src.compile import A7Compiler
2222
from src.tokens import Tokenizer
2323
from src.parser import Parser
24+
from src.ast_nodes import ASTNode, NodeKind
2425
from src.backends.zig import ZigCodeGenerator
26+
from src.errors import CodegenError
2527
from src.passes import NameResolutionPass, TypeCheckingPass, SemanticValidationPass
2628

2729
EXAMPLES_DIR = PROJECT_ROOT / "examples"
@@ -178,6 +180,12 @@ def test_ast_check(self, example, tmp_path):
178180
class TestCodePatterns:
179181
"""Test that specific A7 constructs produce expected Zig patterns."""
180182

183+
def test_unsupported_expression_raises_codegen_error(self):
184+
codegen = ZigCodeGenerator()
185+
186+
with pytest.raises(CodegenError, match="unsupported expression node 'FALL'"):
187+
codegen._emit_expr(ASTNode(NodeKind.FALL))
188+
181189
def test_hello_world(self):
182190
source = '''
183191
io :: import "std/io"

0 commit comments

Comments
 (0)