Skip to content

A user type named like a std module's private type breaks that std generic (Mutex.new with a user MutexState): std generic bodies resolve type names against the user's declarations #1745

Closed

Description

@ehartford

Spec: §18.2 — name precedence is per module; "a user-controlled declaration is never shadowed, merged, or impl-captured by the fallback tier", and std's own declarations are std's. Found on branch gen-push-pull (#1725); reproduces on main's installed compiler and on the gen-push-impl base.

Repro:

use std.sync.Mutex

type MutexState { x: i32 }

fn main:
    let c = MutexState { x: 4 }
    let m = Mutex.new(40)
    m.set(38)
    print(c.x)

Expected: prints 4. Actual:

error: cannot lower projected assignment in 'Mutex.new__receiver__434_4_4' (MIR place 18)
error: code generation failed

Mutex.new[T] (lib/std/sync.w) names its private MutexState; instantiated for the user's call, the name resolves to the user's MutexState. The same happens to any std generic: a user type Box { n: i32 } (test/compile_errors/err_view_dangling.w) made std.task's Pulled[T] { core: Box[PullCore] } fail with "unknown type 'Box' … did you mean 'Box'?", and a user type PullCore breaks g.pull() the same way (so std.task's pull no longer uses Box; the private PullCore name is still exposed to the defect).

Two failures: the wrong resolution itself, and the codegen-phase "cannot lower projected assignment" — Sema accepted a body it had typed against the wrong declaration.

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