-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Protocol typealias fixes #2992
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
Merged
swift-ci
merged 5 commits into
swiftlang:master
from
slavapestov:protocol-typealias-fixes
Jun 12, 2016
Merged
Protocol typealias fixes #2992
swift-ci
merged 5 commits into
swiftlang:master
from
slavapestov:protocol-typealias-fixes
Jun 12, 2016
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This wasn't doing the right thing for TypeAliasDecls. NFC for now, but exposed by some other changes I am working on.
@swift-ci Please test |
This is a big refactoring of resolveTypeInContext() which makes the function clearer to understand by merging various special cases and generalizing the logic for walking parent and superclass contexts to cover more cases. This improves typealiases in protocols a bit: 1) Previously a typealias in a protocol either had to be concrete, or consist of a single path of member types from Self, eg Self.A.B. Lift this restriction, so we can now write things like protocol Fireworks { associatedtype Exploding typealias Exploder = Exploding -> [Exploding] } 2) Protocol typealiases can now be accessed via qualified lookup on concrete types. Getting this working for unqualified lookup requires further refactorings which will be in a subsequent patch.
Avoid calling lookupMemberType() with an existential base altogether. With the previous resolveTypeInContext() patch, a compiler_crasher regressed and hit this, because the behavior of lookupMemberType() changed to return nullptr in fewer cases.
…n-types earlier With the previous resolveTypeInContext() patch, a few compiler crashers regressed with this problem, presumably because we were now performing lookups in more contexts than before. This is a class of problems where we would attempt a recursive validation: 1) Generic signature validation begins for type T 2) Name lookup in type context finds a non-type declaration D nested in T 3) Generic signature validation begins for D 4) The outer generic context of D is T, but T doesn't have a generic signature yet The right way to break such cycles is to implement the iterative decl checker design. However when the recursion is via name lookup, we can try to avoid the problem in the first place by not validating non-type declarations if the client requested a type-only lookup. Note that there is a small semantic change here, where programs that were previously rejected as invalid because of name clashes are now valid. It is arguable if we want to allow stuff like this or not: class A { func A(a: A) {} } or class Case {} enum Foo { case Case(Case) } However at the very least, the new behavior is better because it gives us an opportunity to add a diagnostic in the right place later. The old diagnostics were not very good, for example the second example just yields "use of undeclared type 'Case'". In other examples, the undeclared type diagnostic would come up multiple times, or we would generate a cryptic "type 'A' used within its own definition". As far as I understand, this should not change behavior of any existing valid code.
cfca3ed
to
3127264
Compare
@swift-ci Please test |
@swift-ci Please test and merge |
1 task
milseman
reviewed
Oct 22, 2016
fromType = resolver->resolveGenericTypeParamType(selfType); | ||
|
||
if (assocType) { | ||
// Odd special case, ask Doug to explain it over pizza one day |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍕
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Finally this fixes my earlier patch that got reverted:
14d0be2