Skip to content

Tests: extern c void coverage (§16) #499

Closed

Description

@ehartford

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

  1. Add focused tests without changing compiler behavior unless a test exposes a stale premise.
  2. 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 C void maps to With unit.
  3. Add compile-error coverage that assigning to extern let fails.
  4. Add behavior or check coverage showing extern var assignment 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.
  5. Add a c_import header fixture with extern const int c_const; extern int c_mut; and assert generated/imported surface distinguishes extern let from extern 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 let assignment rejection.
  • Tests cover mutable extern var acceptance.
  • Tests cover c_import const vs non-const C global classification.
  • with build && with build :fixpoint && with build :test pass.

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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions