Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14983] Typealiases supplied by a protocol are interpreted inconsistently #57325

Open
BigZaphod opened this issue Jul 28, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@BigZaphod
Copy link

Previous ID SR-14983
Radar rdar://problem/81277881
Original Reporter @BigZaphod
Type Bug
Environment

Xcode Version 13.0 beta 4 (13A5201i)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: ab0f3b68f670287f4b5ece72af753d0a

Issue Description:

In the following code, there is a typealias defined inside of a protocol that happens to shadow a concrete type of the same name that exists outside of the protocol. When defining a custom type based on that protocol, the compiler appears to chose either the outer scope name or the inner scope one depending on how it is used.

protocol SomeProtocol {
    typealias SomeType = Int
}


struct SomeType {
    static var wrong: SomeType { fatalError() }
}


struct SomeImplementationA: SomeProtocol {
    var property = SomeType()
}


struct SomeImplementationB: SomeProtocol {
    var property: SomeType
}


func someTest() {
    let a = SomeImplementationA(property: 10)  // property is of type SomeProtocol.SomeType (the protocol's Int typealias)

    let b = SomeImplementationB(property: .wrong)  // property is of type SomeType (the outer struct)
}

I would expect the typealias defined by the protocol to always "win" no matter where the type is used as long as I'm inside that context. (I'm not sure what the correct words are here, but hopefully this makes sense.)

@typesanitizer
Copy link

I agree that this behavior seems very strange.

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler in itself label Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants