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-5305] Swift 3.2 source breakage on protocol associated type inference #47880

Open
swift-ci opened this issue Jun 25, 2017 · 2 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.0

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-5305
Radar rdar://problem/32983215
Original Reporter florent.bruneau (JIRA User)
Type Bug

Attachment: Download

Environment

Linux
swift-4.0-DEVELOPMENT-SNAPSHOT-2017-06-23-a-ubuntu16.10

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

md5: e06c397b0e69376779b64f5f31b91adb

Issue Description:

Hi,

I have noticed a regression on code that implements a custom collection between swift 3.1 and swift 3.2 (swift 4.0 nightly build + -swift-version 3).

Here is the code:

struct Foo {
    var keys: UnsafeMutablePointer<UInt32>?
    var values: UnsafeMutablePointer<String>?
    var len: Int

    init(len: Int) {
        self.len = len
    }
}

protocol FooKeyContainer : Collection {
    associatedtype Key;
    typealias Index = Int

    var keys: UnsafeMutablePointer<Key>? { get set }
    var len: Int { get set }

    init(len: Int)
}

extension FooKeyContainer {
    public var startIndex: Int {
        return 0
    }

    public var endIndex: Int {
        return len
    }

    public func index(after pos: Int) -> Int {
        return pos + 1
    }
}


protocol FooKVContainer : FooKeyContainer, ExpressibleByDictionaryLiteral {
    associatedtype Value
    typealias Element = (key: Key, value: Value)

    var values: UnsafeMutablePointer<Value>? { get set }
}

extension FooKVContainer {
    public subscript(pos: Int) -> (key: Key, value: Value) {
        return (key: keys![pos], value: values![pos])
    }
}

extension FooKVContainer {
    public init(dictionaryLiteral newElements: (Key, Value)...) {
        self.init(len: newElements.count)
    }
}

extension Foo : FooKVContainer { }

With swift 3.1 this code compiles without any warning, but with swift 3.2 I got the following error:

blah.swift:55:1: error: type 'Foo' does not conform to protocol 'ExpressibleByDictionaryLiteral'
extension Foo : FooKVContainer { }
^
Swift.ExpressibleByDictionaryLiteral:62:20: note: protocol requires nested type 'Key'; do you want to add it?
    associatedtype Key
                   ^
Swift.ExpressibleByDictionaryLiteral:64:20: note: protocol requires nested type 'Value'; do you want to add it?
    associatedtype Value
                   ^
@belkadan
Copy link
Contributor

cc @DougGregor

@belkadan
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 regression swift 4.0
Projects
None yet
Development

No branches or pull requests

3 participants