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-7605] Overly-exuberant associatedtype deduction? #50147

Open
dabrahams opened this issue May 4, 2018 · 7 comments
Open

[SR-7605] Overly-exuberant associatedtype deduction? #50147

dabrahams opened this issue May 4, 2018 · 7 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-7605
Radar rdar://problem/40985367
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @AnthonyLatsis
Priority Medium

md5: 7a30a5414b3549776db0a34b5c14e882

relates to:

  • SR-5440 Typealias in constrained extension misinterprets the where clause

Issue Description:

It pains me to say it, but I think the code at https://github.com/dabrahams/WhitherSequence/blob/26ebb7d284c825b08b09b8cc6921d82600265ed5/Sequence.swift shouldn't actually compile, because there's nothing driving it to deduce the `Index` type of `Fibonacci`.

@dabrahams
Copy link
Collaborator Author

Here's a reduction against github/master 63856d4:

protocol P {
    associatedtype A
    var a: A { get }
}
extension P where A == Int {
    var a: Int { return 0 }
}
struct X : P {  } // Compiles?

If this is working as intended, I think we made a mistake in the semantics of the generics system. It certainly doesn't match my mental model for how things are supposed to work. I would expect it if I had written associatedtype A = Int or added

extension P { typealias A = Int }

(which incidentally doesn't compile). To put it in English, I expect extension P where A == Int to be a conditional extension that only applies when the associated type is deduced to be `Int` by other means, not to influence deduction of the associated type on which it is itself conditional.

@belkadan
Copy link
Contributor

belkadan commented May 7, 2018

cc @huonw, @rjmccall

@rjmccall
Copy link
Member

rjmccall commented May 7, 2018

I agree with Dave that we shouldn't default anything in order to match a conditional conformance.

@dabrahams
Copy link
Collaborator Author

@swift-ci create

@dabrahams
Copy link
Collaborator Author

This is related to SR-7610

@jepers
Copy link

jepers commented Jun 13, 2018

I linked as related to SR-5440, because it seems so similar to eg the following (even though it's not involving protocols, only constrained extensions):

This (invalid) program compiles successfully, because the compiler misinterprets the where clause:

struct X<T> {
    var a : A
}
extension X where T == Never {
    typealias A = Int
}
let x = X<Int>(a: 123)

@huonw
Copy link
Mannequin

huonw mannequin commented Jun 15, 2018

Note that this isn't a conditional conformance. cc @DougGregor since it's an associated type inference thing.

@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
Projects
None yet
Development

No branches or pull requests

4 participants