Skip to content

Private functions with the same name in two modules of one package collide ('symbol is not visible from this module') #1139

Closed

Description

@ehartford

Two modules of one package each define a private fn helper; a module calling its OWN helper fails to compile.

Repro (package pk, lib/pk/a.w, lib/pk/b.w, src/main.w):

// lib/pk/a.w
fn helper(x: i32) -> i32: x + x
pub fn a_probe() -> i32: helper(1)

// lib/pk/b.w
fn helper(x: i32) -> i32: x * 3
pub fn b_probe() -> i32: helper(1)

// src/main.w
use pk.a
use pk.b
fn main: assert(b_probe() + a_probe() == 5)
$ with run src/main.w
error: symbol 'helper' is not visible from this module
 --> lib/pk/a.w:2:26
2 | pub fn a_probe() -> i32: helper(1)

Same with the seed (v0.15.2.1), main's release binary and the fnabi-phase0 tree; also when b imports a instead of main importing both. Expected: a private symbol is private to its module (spec §18, D29); two modules may each have their own. The resolver appears to key private functions by bare name across the package.

Found by the Phase 2 migrator fixture behav_migrate_header_inline_owner: a header no unit owns keeps a static inline copy per includer (the C model), which is exactly this shape. The 13 TommyDS units each carry a private tommy_ilog2_u32 and DO compile as the std.tommyds bundle, so the bundle/std path resolves differently from a user package.

Activity

  1. joshhickson commented on Sep 17, 2026

    @joshhickson
    Contributor

    Another instance that looks like the same resolution problem, this time between a user file and std.

    std/string.w declares pub fn is_digit and calls it from is_alnum (line 199). Declaring a function with the same name in user code breaks that call inside std, even when the user file never uses std.string:

    // shadow.w
    fn is_digit(ch: i32) -> bool: ch in 48..=57
    fn main:
        print(f"{is_digit(50)}")
    
    $ with run shadow.w
    error: symbol 'is_digit' is not visible from this module
     --> <embedded-std>/std/string.w:199:20
    199 |     is_alpha(c) or is_digit(c)
        |                    ^^^^^^^^
    error: run failed
    

    Renaming the user function to is_digit_mine makes the same file print true. The same error appears from src/main.w in a project.

    Two differences from the original report that may matter for the fix:

    • The callee's own declaration is pub here, so it isn't only private-vs-private: is_alnum's call to its own module's is_digit appears to resolve to the user's private declaration instead.
    • On the last paragraph above: same-named privates among std bundle units resolve fine, but a user declaration can still capture a call inside std.

    The diagnostic also points into <embedded-std> and never mentions the user's declaration, so from the user's side there's no hint that their own function name is the cause.

    Tested on v0.15.2.1, Windows x86_64.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce.

    $ cat lib/pk/a.w
    fn helper(x: i32) -> i32: x + x
    pub fn a_probe() -> i32: helper(1)
    $ cat lib/pk/b.w
    fn helper(x: i32) -> i32: x * 3
    pub fn b_probe() -> i32: helper(1)
    $ cat src/main.w
    use pk.a
    use pk.b
    fn main:
        assert(b_probe() + a_probe() == 5)
        print("ok")
    $ with run src/main.w
    ok
    
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