Repository navigation
Description
Summary
Add missing tests for manual extern C void/unit behavior and C global mutability. The issue appears coverage-only: the implementation has relevant surfaces, but the requirements campaign found no committed tests for several §16.3 rules.
Spec
§16.3 manual extern declarations are raw ABI declarations and calls require unsafe unless safely wrapped (docs/with-specification.md:8290). §16.3b says C globals use extern var or extern let, extern let cannot be assigned, extern var stores to the global, the type must be concrete, and access does not require unsafe (docs/with-specification.md:8307). c_import emits extern var for non-const globals and extern let for const-qualified globals (docs/with-specification.md:8325).
Current state
c_import emits const C variables as evaluated let or extern let, and mutable variables as extern var unless migrator no-c-export mode requests local var (src/CImport.w:1840). Sema assignment diagnostics already reject read-only places such as const/global-let forms (src/SemaCheck.w:5102). Manual extern calls are part of unsafe call enforcement through call checking and extern-function tracking (src/SemaCheck.w:8168). The gap is test coverage, not a known implementation bug.
Implementation plan
- Add focused tests without changing compiler behavior unless a test exposes a stale premise.
- Cover manual
extern fn foo() -> void/ unit return syntax and call lowering in a behavior test. If With syntax uses omitted return for unit, make the test match accepted language syntax and document that Cvoidmaps to With unit. - Add compile-error coverage that assigning to
extern letfails. - Add behavior or check coverage showing
extern varassignment is accepted and generates a store. Use a small C shim or existing libc symbol only if deterministic across hosts; otherwise use emitted-C/IR assertions. - Add a
c_importheader fixture withextern const int c_const; extern int c_mut;and assert generated/imported surface distinguishesextern letfromextern var.
Test plan
Add test/behavior/behav_extern_c_void.w for a void-return extern declaration and unsafe call. Add test/compile_errors/err_extern_let_assignment.w. Add test/behavior/behav_c_import_extern_globals.h and .w to import const and mutable globals and inspect/check the resulting bindings. If runtime linking to test globals is awkward, add a with check-only test and a generated binding snapshot assertion.
Acceptance criteria
- Tests cover extern C void/unit return acceptance.
- Tests cover
extern letassignment rejection. - Tests cover mutable
extern varacceptance. - Tests cover
c_importconst vs non-const C global classification. with build && with build :fixpoint && with build :testpass.
Dependencies
None.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 16.3.3.3, 16.3.3.5, 16.3.3.7, 16.3.3.9.
Activity
ehartford commentedon Jul 3, 2026
Closing — extern-let assignment (err_extern_let_assignment) and c_import const-global assignment (err_c_import_const_global_assign) rejections pinned (6c59303); manual-extern-unsafe + C void→Unit surface + extern-var already covered (err_manual_extern_call_requires_unsafe, behav_unit_and_c_void_surface, issue113_*). §16.3.
test: coverage-sweep batch 1 (#495 #496 #521 #518 #529 #492 #499)