Skip to content

compiler: extern var redeclaration shadows var definition in whole-program compilation #113

Closed

Description

@ehartford

Summary

When compiling a program that imports multiple modules via `use`, if module A defines `var x: T` and module B declares `extern var x: T`, the compiler reports "shadowing is not allowed for 'x'".

Reproduction

```with
// Module A (pcre2_tables.w): defines the variable
var _pcre2_ascii_to_ebcdic_1047_8: *u8

// Module B (pcre2_script_run.w): references it
extern var _pcre2_ascii_to_ebcdic_1047_8: *u8
```

When both are imported into a single program, the compiler sees both declarations and treats the `extern var` as a shadowing redeclaration.

Expected behavior

`extern var x: T` should be recognized as a reference to the existing `var x: T` definition, not as a new shadowing declaration. This is the same semantics as C's `extern` — it declares that the variable exists somewhere else, it doesn't create a new one.

Impact

Blocks importing the full PCRE2 library in a single program. Every PCRE2 module has `extern var` declarations for shared symbols (from the preamble), and these conflict with the `var` definitions in pcre2_tables.w.

Relation to #105

#105 fixed `let` shadowing for shared imports. This is the same issue for `extern var` vs `var`.

Activity

  1. ehartford commented on Apr 12, 2026

    @ehartford
    ContributorAuthor

    Retested on the current checkout. './out/bin/with-stage2 run test/behavior/issue113_extern_var_redeclaration.w' now passes, so the original whole-program 'extern var' shadowing repro no longer reproduces.

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