swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.64k stars 10.38k forks source link

[SR-1874] Calling subclass's associated type in a generic function cause compiler error #44483

Open swift-ci opened 8 years ago

swift-ci commented 8 years ago
Previous ID SR-1874
Radar None
Original Reporter hanjustin (JIRA User)
Type Bug
Environment Version 7.3.1 (7D1014) Swift 2.2
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 09f388a77933d3d05bd7744150e9c9e8

Issue Description:

protocol AssociatedTypeProtocol {
    associatedtype RawValue: RawRepresentable
}

class ParentClass: AssociatedTypeProtocol {
    enum RawValue: String {
        case parentRawValue
    }
}

class SubClass: ParentClass {
    enum RawValue: String {
        case subRawValue
    }
}

func genericTest<T: AssociatedTypeProtocol>(object: T, stringEnum: T.RawValue) {

}

func test() {
    genericTest(ParentClass(), stringEnum: .parentRawValue)
    genericTest(SubClass(), stringEnum: .parentRawValue)
    genericTest(SubClass(), stringEnum: .subRawValue)
    // The last line causes Command failed due to signal: Segmentation fault: 11
    // I also got auto completion for both .parentRawValue & .subRawValue for the last line, which is I expected, but not sure if that is intended.
}
belkadan commented 8 years ago

You can't change an associated type in a subclass today, right @jckarter?

jckarter commented 8 years ago

Yeah, and I don't think it would be sound to be able to. The subclass inherits the conformance as-is from the parent class.

Dante-Broggi commented 6 years ago

Is this resolved? If so, this should be closed.