Skip to content

[SR-6125] Compiles with wmo but reference to invalid associated type without wmo #48680

@jepers

Description

@jepers
Previous ID SR-6125
Radar rdar://problem/34956654
Original Reporter @jepers
Type Bug

Attachment: Download

Environment

Xcode 9 beta 1, using toolchain development-snapshot-2017-10-10

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

md5: 6506c68f4427aeaeae0775a16fbee482

Issue Description:

The following two files (also attached) compiles if using -wmo, but results in the below error without -wmo.

main.swift:

struct Vector1<Element> : Vector {
    var e0: Element
    init(elementForIndex: (VectorIndex1) -> Element) {
        e0 = elementForIndex(.i0)
    }
    subscript(index: Index) -> Element {
        get { return e0 }
        set { e0 = newValue }
    }
}

Other.swift:

protocol VectorIndex {
    associatedtype Vector8 : Vector where Vector8.Index == Self, Vector8.Element == UInt8
}
enum VectorIndex1 : VectorIndex {
    case i0
    typealias Vector8 = Vector1<UInt8>
}
protocol Vector {
    associatedtype Index: VectorIndex
    associatedtype Element
    init(elementForIndex: (Index) -> Element)
    subscript(index: Index) -> Element { get set }
}
extension Vector where Index == VectorIndex1 {
    init(_ e0: Element) { fatalError() }
}

Compiles fine with -wmo:

$ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-10-10-a.xctoolchain/usr/bin/swiftc -wmo main.swift Other.swift

Compiling without -wmo results in the following error:

$ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-10-10-a.xctoolchain/usr/bin/swiftc main.swift Other.swift  
main.swift:6:22: error: reference to invalid associated type 'Index' of type 'Vector1<Element>'  
subscript(index: Index) -> Element {

Metadata

Metadata

Assignees

No one assigned

    Labels

    associated type inferencebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesswift 6.0type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions