Skip to content

Selective imports are not selective: use m.X makes every public name of m visible #1744

Closed

Description

@ehartford

Spec: §18.2 — "Names are imported with use" (use std.collections.{HashMap, HashSet}, use math.vector.{Vec3, dot, cross}); a named import introduces the names it selects.

Repro (base = branch gen-push-impl d06b5bc release binary; installed main the same):

sa.w

pub let X = 1
pub let Y = 5
pub fn fy() -> i32: 6

s1.w

use sa.X
fn main:
    print(Y)
    print(fy())

Actual: prints 5 and 6. Resolve maps use sa.X to an import edge to sa.w and Sema's visibility (module_is_visible_from_current / decl_visible_from_current) asks only whether the module is imported, so the selection is ignored.

Expected: Y and fy are not visible — an error naming the named import and the spelling that brings them in (use sa.{X, Y, fy} or use sa).

Note: on branch ruled-fixes (#1221) Resolve now records each import's selection (ResolvedImport.selected → Sema.module_import_selected), and precedence between colliding module values uses it; general visibility still ignores it. Enforcing it everywhere may turn existing programs (and the compiler tree) that lean on the leak into errors, so it wants a sweep of the corpora first.

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