Skip to content

[Migrator] Migrate references to shorthand closure params (e.g. $0, $1) where affected by SE110 #9711

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

nathawes
Copy link
Contributor

In Swift 3:

  1. a closure referring to $1 or above type checked against a function type that takes a single tuple argument with that arity
  2. a closure referring only to $0 (or $0.1 etc) type checked against a function type that takes multiple arguments

but neither compiles in Swift 4. This patch migrates shorthand references for:

  1. by prefixing "0." in front of the existing references, e.g. $1 to $0.1
  2. by removing the leading 0. if one exists or substituting a tuple of the correct arity if it doesn't, e.g. $0.1 to $1 and $0 to ($0, $1, $2)

Resolves rdar://problem/31969538

…1) where affected by SE110

In Swift 3:
 1) a closure referring to $1 or above type checked against a function type that takes a single tuple argument with that arity
 2) a closure referring only to $0 (or $0.1 etc) type checked against a function type that takes multiple arguments
but neither compiles in Swift 4.

This patch migrates shorthand references for
  1) by prefixing "0." in front of the existing references, e.g. "$1" to "$0.1"
  2) by removing the leading 0. if one existing or substituting a tuple of the correct arity if it doesn't, e.g. "$0.1" to "$1" and "$0" to "($0, $1, $2)"

Resolves rdar://problem/31969538
@nathawes nathawes requested a review from bitjammer May 17, 2017 21:22
@@ -22,9 +22,115 @@ using namespace swift;
using namespace swift::migrator;

namespace {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a doc comment here describing what this does and how it's used below?


class ShorthandFinder: public ASTWalker {
private:
llvm::DenseMap<ParamDecl*, std::vector<Expr*>> References;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment here explaining the key and value types, if you don't mind.

Copy link
Contributor

@bitjammer bitjammer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG!

@nathawes
Copy link
Contributor Author

@swift-ci Please smoke test

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.

2 participants