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

Error when one associated type is constrained to another. #10053

Merged
merged 1 commit into from
Jun 2, 2017

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Jun 2, 2017

(...is constrained to be a subtype of another)

Previously the compiler would just mark the entry in the inheritance clause invalid and move on without emitting any errors; in certain circumstances in no-asserts builds this could actually lead to everything working "correctly" if all conforming types happened to pick the same concrete type for both associated types. In Swift 4 this can actually be enforced with a same-type requirement, which will guarantee that the two associated types are the same even in generic contexts.

This fix avoids assertions and crashes, but the diagnostic is still incorrect, and in the simple case of the inheritance clause it's redundant. Doing something better and possibly even downgrading it to a warning in Swift 3 mode is tracked by SR-4981 / rdar://problem/32409449.

@jrose-apple
Copy link
Contributor Author

The actual meat of this patch was written by Slava. I just cleaned it up a little and added tests. I'm not skilled enough in the generic signature builder or the iterative decl checker to know the best way to fix things up here without spending a good deal more time.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

jrose-apple commented Jun 2, 2017

Also, @JohnEstropia, I thought you'd like to know that this wasn't doing what you wanted it to in Swift 3.1. A typealias would probably work if you don't need compatibility with Swift 3.0. (We discovered this problem thanks to CoreStore's presence in the source compat suite.)

@slavapestov
Copy link
Member

LGTM! As for the Swift 3 compatibility story, I don't have any strong opinions. Leaving it as an error might be best, because clearly we're not doing (or able to do) what the user meant here.

(...is constrained to be a subtype of another)

Previously the compiler would just mark the entry in the inheritance
clause invalid and move on without emitting any errors; in certain
circumstances in no-asserts builds this could actually lead to
everything working "correctly" if all conforming types happened to
pick the same concrete type for both associated types. In Swift 4 this
can actually be enforced with a same-type requirement, which will
guarantee that the two associated types are the same even in generic
contexts.

This fix avoids assertions and crashes, but the diagnostic is still
incorrect, and in the simple case of the inheritance clause it's
redundant. Doing something better and possibly even downgrading it to
a warning in Swift 3 mode is tracked by rdar://problem/32409449.

Initial patch by Slava, fixed up by me.
@jrose-apple
Copy link
Contributor Author

Even if we don't do anything for Swift 3 it would be nice to clean up the error so it actually said the right thing. :-)

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 63bc717 into apple:master Jun 2, 2017
@jrose-apple jrose-apple deleted the assock-assosh branch June 2, 2017 02:45
@JohnEstropia
Copy link

Also, @JohnEstropia, I thought you'd like to know that this wasn't doing what you wanted it to in Swift 3.1. A typealias would probably work if you don't need compatibility with Swift 3.0. (We discovered this problem thanks to CoreStore's presence in the source compat suite.)

@jrose-apple I'll refactor this part of the library as I feel it's fighting the type system anyway. Thanks for the heads-up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants