Skip to content

Sema: an import-gated std type leaks into a module that never imported it, depending on body-check order; on Windows check src\main.w fails where check W:/…/src/main.w passes (§18.1) #1955

Closed

Description

@ehartford

Found verifying #1267/#1330 on win10 (main 1688728 and main tip 30f89aa, seed-built stage1).

Repro

darwin-aarch64 (installed with v0.15.3.0, main 1688728), leak.w:

use compiler.Link
fn main:
    var sb = StringBuilder.new()
    sb.push_str("a")
    print(sb.to_str())
$ with check leak.w
ok

StringBuilder is import-gated (§18.1: the same program without use compiler.Link is rejected with "'StringBuilder' requires an explicit import"). It resolves only because compiler.Link has use std.string.StringBuilder — a bare use compiler.Link leaks Link's own imports into the importer. with analyze leak.w 'select:stage=sema,name~StringBuilder' shows the type registered from <embedded-std>/std/string.w.

windows-x86_64 (win10, same source, same stage1 — the verdict depends on how the path is spelled, i.e. on body-check order):

> out\bootstrap\bin\with-stage1.exe check src\main.w
error: 'StringBuilder' requires an explicit import (§18.1); add: use std.string.StringBuilder
 --> src\main.w:547:15
(…four more, lines 567/612/643/670)
> out\bootstrap\bin\with-stage1.exe check W:/verify-2/src/main.w
ok

Both at 1688728 and at 30f89aa (after #1945 / 45cc685). The build passes absolute forward-slash paths, so stage2 builds; the selfhost-windows failure probe (with-stage1 build out/gen/main.w) passes only because it is spelled with forward slashes.

Where

src/Sema.w lookup_named_type_filtered (line 4324 at 1688728):

        if named_tid != 0 and (saw_recorded == 0 or saw_named_tid == 0):
            return named_tid

named_types is the global sym→tid table; it holds StringBuilder once any module's use std.string.StringBuilder registered it. When the importer's body is checked after that module, the gated lookup falls through every recorded candidate (none visible from the current module) and returns the global entry — the name is visible without an import. When the importer is checked first (the backslash spelling orders it differently on Windows), the fallback finds nothing and §18.1 fires. The D29 gate (std_gated_import_note) is only consulted after this lookup fails, so the leak bypasses it.

Consequences

  • src/main.w, src/CodegenDispatch.w, src/compiler/Frontend.w (and the dead tool src/tools/generate_embedded_stdlib.w) use StringBuilder with no import and compile only through the leak; branch fix-std-imports adds the explicit use std.string.StringBuilder to the three compiled files.
  • Make semantic verdicts independent of body-check order #1945's reverse-order checker did not expose this: the order difference here comes from the module path spelling (\ vs /) on Windows, not from reversing bodies.

Expected: an import-gated name resolves only through the current module's own imports, in every body-check order and whatever the path spelling; the fallback at Sema.w:4324 must not return a gated std type the current module never imported.

Activity

  1. added 7 commits that reference this issue on Oct 2, 2026
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