Skip to content

A std-package module's pub type isize shadows the builtin in every module of the package (D100), breaking std.collections #2552

Closed

Description

@ehartford

A module of package std declaring pub type isize = c_long (the migration of STC's typedef ptrdiff_t isize; into lib/std/stc/defs.w) makes every other std module read isize as that alias: checking any std.stc module with --no-prelude --bundle-corpus std/stc fails inside std.collections, which the module does not import:

error: if arms have types `i64` and `isize`; no implicit conversion joins them (§4.2.6), so spell one arm with `as`
 --> <embedded-std>/std/collections.w:230:23
230 |             let mid = if lo + width < n: lo + width else: n

n is keys.len() (the builtin isize), lo and width are annotated isize, which now resolves to the corpus's alias. A module importing std.collections from outside the package sees no error; a program declaring pub type isize = i64 shadows the builtin inside that module only (compiles, prints 3 for f(3)).

Package visibility (D100) lets a pub declaration reach its sibling modules without an import, and the name lookup puts a package-level declaration ahead of a builtin type name, so one corpus typedef silently retypes the standard library. Expected: a builtin type name is not shadowed across module boundaries by package visibility (a module's own declaration may shadow in that module, as now), or the declaration is refused with the name's origin.

Workaround on the STC branch: the migrator renames a C typedef spelling a With builtin type (isize → isize_), as it renames prelude names (#749). The compiler side stays open: any std-package module can still do this by hand.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce for the compiler side. The corpus no longer declares pub type isize (the migrator renames it to isize_), and a package module that declares one does not change isize in its siblings:

    $ cat lib/pk/a.w
    pub type isize = i32
    $ cat lib/pk/b.w
    pub fn count(xs: &List[i64]) -> i64:
        let n: isize = xs.len()
        let wide: i64 = 1 << 40
        if n > 0: wide else: 0
    $ with run src/main.w   # use pk.a; use pk.b; print(count(&xs))
    1099511627776
    
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