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-6125] Compiles with wmo but reference to invalid associated type without wmo #48680

Closed
jepers opened this issue Oct 12, 2017 · 3 comments · Fixed by #69826
Closed

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

jepers opened this issue Oct 12, 2017 · 3 comments · Fixed by #69826
Labels
associated type inference bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances swift 6.0 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@jepers
Copy link

jepers commented Oct 12, 2017

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 {
@belkadan
Copy link
Contributor

@swift-ci create

@jepers
Copy link
Author

jepers commented Jun 4, 2018

Issue remains in dev snapshot 2018-06-01

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 13, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 14, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 14, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
slavapestov added a commit to slavapestov/swift that referenced this issue Nov 14, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
@slavapestov
Copy link
Member

Fixed by #69826

slavapestov added a commit to slavapestov/swift that referenced this issue Nov 17, 2023
…request cycle

This implements a structural walk over the TypeRepr to catch
situations where we attempt to infer `A` from `func f(_: A)`,
which references the concrete `A` that will be synthesized
in the conforming type.

Fixes:
- rdar://34956654 / apple#48680
- rdar://38913692 / apple#49066
- rdar://56672411
- apple#50010
- rdar://81587765 / apple#57355
- rdar://117442510
@AnthonyLatsis AnthonyLatsis added type checker Area → compiler: Semantic analysis conformances Feature → protocol: protocol conformances associated type inference unexpected error Bug: Unexpected error swift 6.0 labels Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
associated type inference bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances swift 6.0 type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants