Skip to content

Commit a6f7a8e

Browse files
committed
[Parser] Set local discriminator to ParamDecls
We have to discriminate between params and local variables.
1 parent 6496175 commit a6f7a8e

14 files changed

+152
-36
lines changed

include/swift/Parse/Parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ class Parser {
761761
ParserStatus parseLineDirective(bool isLine = false);
762762

763763
void setLocalDiscriminator(ValueDecl *D);
764+
void setLocalDiscriminatorToParamList(ParameterList *PL);
764765

765766
/// Parse the optional attributes before a declaration.
766767
bool parseDeclAttributeList(DeclAttributes &Attributes,

lib/Parse/ParseDecl.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,14 @@ void Parser::setLocalDiscriminator(ValueDecl *D) {
24092409
D->setLocalDiscriminator(discriminator);
24102410
}
24112411

2412+
void Parser::setLocalDiscriminatorToParamList(ParameterList *PL) {
2413+
for (auto P : *PL) {
2414+
if (!P->hasName() || P->isImplicit())
2415+
continue;
2416+
setLocalDiscriminator(P);
2417+
}
2418+
}
2419+
24122420
void Parser::delayParseFromBeginningToHere(ParserPosition BeginParserPosition,
24132421
ParseDeclOptions Flags) {
24142422
auto CurLoc = Tok.getLoc();
@@ -4282,6 +4290,8 @@ bool Parser::parseGetSetImpl(ParseDeclOptions Flags,
42824290

42834291
// Establish the new context.
42844292
ParseFunctionBody CC(*this, TheDecl);
4293+
for (auto PL : TheDecl->getParameterLists())
4294+
setLocalDiscriminatorToParamList(PL);
42854295

42864296
// Parse the body.
42874297
SmallVector<ASTNode, 16> Entries;
@@ -4373,6 +4383,8 @@ void Parser::parseAccessorBodyDelayed(AbstractFunctionDecl *AFD) {
43734383
// Re-enter the lexical scope.
43744384
Scope S(this, AccessorParserState->takeScope());
43754385
ParseFunctionBody CC(*this, AFD);
4386+
for (auto PL : AFD->getParameterLists())
4387+
setLocalDiscriminatorToParamList(PL);
43764388

43774389
SmallVector<ASTNode, 16> Entries;
43784390
parseBraceItems(Entries);
@@ -5325,6 +5337,8 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
53255337

53265338
// Establish the new context.
53275339
ParseFunctionBody CC(*this, FD);
5340+
for (auto PL : FD->getParameterLists())
5341+
setLocalDiscriminatorToParamList(PL);
53285342

53295343
// Check to see if we have a "{" to start a brace statement.
53305344
if (Tok.is(tok::l_brace)) {
@@ -5395,6 +5409,8 @@ bool Parser::parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD) {
53955409
// Re-enter the lexical scope.
53965410
Scope S(this, FunctionParserState->takeScope());
53975411
ParseFunctionBody CC(*this, AFD);
5412+
for (auto PL : AFD->getParameterLists())
5413+
setLocalDiscriminatorToParamList(PL);
53985414

53995415
ParserResult<BraceStmt> Body =
54005416
parseBraceItemList(diag::func_decl_without_brace);
@@ -6257,6 +6273,8 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
62576273
} else {
62586274
// Parse the body.
62596275
ParseFunctionBody CC(*this, CD);
6276+
for (auto PL : CD->getParameterLists())
6277+
setLocalDiscriminatorToParamList(PL);
62606278

62616279
if (!isDelayedParsingEnabled()) {
62626280
if (Context.Stats)

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,7 @@ ParserResult<Expr> Parser::parseExprClosure() {
27312731
if (params) {
27322732
// Add the parameters into scope.
27332733
addParametersToScope(params);
2734+
setLocalDiscriminatorToParamList(params);
27342735
} else {
27352736
// There are no parameters; allow anonymous closure variables.
27362737
// FIXME: We could do this all the time, and then provide Fix-Its

test/refactoring/rename/Outputs/local/casebind_1.swift.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func test4(arg: () throws -> Void) {
3939
}
4040
}
4141

42-
43-
44-
45-
42+
func test5(_ x: Int) {
43+
let x = x
44+
print(x)
45+
}
4646

test/refactoring/rename/Outputs/local/casebind_2.swift.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func test4(arg: () throws -> Void) {
3939
}
4040
}
4141

42-
43-
44-
45-
42+
func test5(_ x: Int) {
43+
let x = x
44+
print(x)
45+
}
4646

test/refactoring/rename/Outputs/local/catch_1.swift.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func test4(arg: () throws -> Void) {
3939
}
4040
}
4141

42-
43-
44-
45-
42+
func test5(_ x: Int) {
43+
let x = x
44+
print(x)
45+
}
4646

test/refactoring/rename/Outputs/local/catch_2.swift.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func test4(arg: () throws -> Void) {
3939
}
4040
}
4141

42-
43-
44-
45-
42+
func test5(_ x: Int) {
43+
let x = x
44+
print(x)
45+
}
4646

test/refactoring/rename/Outputs/local/ifbind_1.swift.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func test4(arg: () throws -> Void) {
3939
}
4040
}
4141

42-
43-
44-
45-
42+
func test5(_ x: Int) {
43+
let x = x
44+
print(x)
45+
}
4646

test/refactoring/rename/Outputs/local/ifbind_2.swift.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func test4(arg: () throws -> Void) {
3939
}
4040
}
4141

42-
43-
44-
45-
42+
func test5(_ x: Int) {
43+
let x = x
44+
print(x)
45+
}
4646

test/refactoring/rename/Outputs/local/localvar_1.swift.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func test4(arg: () throws -> Void) {
3939
}
4040
}
4141

42-
43-
44-
45-
42+
func test5(_ x: Int) {
43+
let x = x
44+
print(x)
45+
}
4646

0 commit comments

Comments
 (0)