Skip to content

stage1 (source-compiled std.re) leaks its pub globals into every user program's global scope: const PACKAGE is "shadowing is not allowed for 'PACKAGE'" #1703

Closed

Description

@ehartford

On a stage1 built in a worktree (:dev, std.re compiled from source under out/gen rather than the .wo bundle), lib/std/re/defs.w's pub let PACKAGE = "pcre2" (and PACKAGE_NAME, PACKAGE_BUGREPORT, …) is visible in every user program's global scope:

comptime fn build() -> i32: 2
const PACKAGE: i32 = comptime build()
fn main:
    print(PACKAGE)

stage1: error: shadowing is not allowed for 'PACKAGE'; the release binary (main c7ac882) prints 2. Any const named PACK/Pkg/package passes; only names that collide with std.re's globals fail, so test/behavior/behav_comptime_aggregate_freeze.w passes in the battery (release binary) and fails on stage1.

Two defects: a module's pub let globals must not be in scope for a program that never imports it, and stage1 and the release binary must agree (#729 class: test-runner-only / stage-only differences). Found while running the behavior corpus on a stage1 for #1702.

Activity

  1. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Root cause is general, not stage1-only. Two things, verified on main d7a3d84's release binary with a three-module project:

    1. Imports are transitive. main with only use helper resolves helper2's deep() and PACKAGE because module_is_visible_from_current walks the import graph. §18.2's precedence lists explicit imports, the prelude and the std fallback — nothing transitive. Fixed in the draft PR (direct edges only; the compiler tree checks unchanged), pinned by behav_imports_are_not_transitive.w.
    2. The stage1 PACKAGE case is a flat-scope global collision. A source-compiled engine corpus binds its pub let globals as bundle-interface globals (one program-wide table, D39/D52), so a module-level const PACKAGE is "one symbol declared twice" (the .wo path never binds them, hence release passes). A lexical let PACKAGE now shadows it (§18.2 tier 1) and the diagnostic names the collision. Whether a module-level declaration shadows another module's flat global (§18.2 tier 2 vs D52's flat table) is a ruling; brief sent to Eric.
  2. added 6 commits that reference this issue on Sep 27, 2026
    682b77a
    1b22861
    8f0e819
    bff895a
    9307016
    7b56d3f
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