Skip to content

[5.0] [Name lookup] Enable shadowing for type lookup and of the Swift module. #21378

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

Conversation

DougGregor
Copy link
Member

Tweak the shadowing rules in two ways:

  1. For unqualified type lookup, apply shadowing rules. Without this, we
    would always get an ambiguity if there were two types with the same name,
    so this should be a strict improvement.
  2. Allow a name introduced in any other module to shadow a name in the
    Swift standard library. This is (another) weak form of a more sensible,
    generalized rule that would use the import graph to describe shadowing.

Together, these tweaks allow the Result type that was recently introduced in
the standard library to exist without breaking source compatibility for
Swift code that is already using a Result type. The user Result type will
shadow (hide) the Swift one. The latter can be spelled Swift.Result if it
is needed by such code.

… rather than co-opting NULL, which is a valid CanType type.
Tweak the shadowing rules in two ways:

1) For unqualified type lookup, apply shadowing rules. Without this, we
would always get an ambiguity if there were two types with the same name,
so this should be a strict improvement.
2) Allow a name introduced in any other module to shadow a name in the
Swift standard library. This is (another) weak form of a more sensible,
generalized rule that would use the import graph to describe shadowing.

Together, these tweaks allow the Result type that was recently introduced in
the standard library to exist without breaking source compatibility for
Swift code that is already using a Result type. The user Result type will
shadow (hide) the Swift one. The latter can be spelled Swift.Result if it
is needed by such code.

Fixes rdar://problem/46767892.
We’re going to need to use this in GenericSignature.cpp. NFC
Narrow the recently-introduced shadowing rule for types so that it only
applies to non-member types. Member types lack a reasonable syntax for
specifying precisely which module to look into, and there are a few use
cases where the type checker will pick a type that would be shadowed by
the new rule.

Fixes a source-compatibility regression introduced by the shadowing rule.
When substituting type parameters to compute a canonical type within a
given generic context, also handle the case where the type parameter is
directly known to be a concrete type. The type checker won’t do this, but 
SourceKit does. 

Fixes a regression in SourceKit/DocSupport/doc_stdlib.swift.
@DougGregor DougGregor requested a review from a team as a code owner December 17, 2018 18:38
@DougGregor
Copy link
Member Author

Note that this only makes sense to test on top of #21225

@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7b87af3

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@DougGregor
Copy link
Member Author

Huh. It almost looks like SwiftPM isn't picking up a newer Swift, because it's failing with the ambiguity that this change fixes.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7b87af3

@DougGregor DougGregor merged commit d8ad1d8 into swiftlang:swift-5.0-branch Dec 18, 2018
@DougGregor DougGregor deleted the shadow-of-the-resultus-5.0 branch December 18, 2018 01:54
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.

3 participants