Skip to content

stage2: Private declarations confound name resolution in declaring file scope #13077

@amp-59

Description

@amp-59

Zig Version

0.10.0-dev.4213+91b05ad47

Steps to Reproduce

Compile test program with zig test name_resolution_error/file_1.zig.

Three files to reproduce:

name_resolution_error/imports.zig:

const file_0 = @import("./file_0.zig");
const file_1 = @import("./file_1.zig");

pub usingnamespace file_0;
pub usingnamespace file_1;

name_resolution_error/file_0.zig:

pub const A = struct {};

name_resolution_error/file_1.zig:

const imports = @import("./imports.zig");

const A = struct {};

test {
    _ = @as(imports.A, undefined);
}

Expected Behavior

Public A declared in file_0 is resolved unambiguously via imports namespace. As with stage 1:

$ zig test -fstage1 name_resolution_error/file_1.zig
All 1 tests passed.

Namespace name_resolution_error/imports.zig behaviour equivalent to:

const file_0 = @import("./file_0.zig");
const file_1 = @import("./file_1.zig");

pub const A = file_0.A;

Actual Behavior

As is, private A declared in file_1 exposed by imports:

$ zig test name_resolution_error/file_1.zig
name_resolution_error/file_1.zig:7:20: error: ambiguous reference
    _ = @as(imports.A, undefined);
            ~~~~~~~^~
name_resolution_error/file_0.zig:4:5: note: declared here
pub const A = struct {};
~~~~^~~~~~~~~~~~~~~~~~~
name_resolution_error/file_1.zig:4:1: note: declared here
const A = struct {};
^~~~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions