Skip to content

Allow discoverable, simple disambiguation between module & type of the same name (e.g. Foo.Foo) #62639

Open
@weissi

Description

@weissi

Currently, if you have a module & a type within that module with the same name, you'll be in trouble if some other module also has that type.

Example:

// main
import Foo
import Bar

Foo.Foo()

// MODULE: Foo
public struct Foo {
    public init() {
        print("Foo.Foo")
    }
}

// MODULE: Bar
public struct Foo {
    public init() {
        print("Foo.Foo")
    }
}

Error:

TestApp/main.swift:5:5: error: reference to member 'Foo' cannot be resolved without a contextual type
Foo.Foo()
    ^

Yes, I know you can resort to

// main
import Foo
import Bar
import struct Foo.Foo // <-- this is the disambiguation

Foo()

but that's cumbersome and undiscoverable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselftype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions