Skip to content

Commit 03668ee

Browse files
authored
Merge pull request #4243 from jrose-apple/swift-3-where-oh-where-has-my-composition-gone
[Parse] Fix fix-it for old-style 'where' clauses. (#4198)
2 parents 2c415d0 + 44ffa19 commit 03668ee

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

lib/Parse/ParseGeneric.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,7 @@ Parser::diagnoseWhereClauseInGenericParamList(const GenericParamList *
183183
// as written all the way to the right angle bracket (">")
184184
auto LastGenericParam = GenericParams->getParams().back();
185185
auto EndOfLastGenericParam =
186-
Lexer::getLocForEndOfToken(SourceMgr,
187-
LastGenericParam->getLoc());
188-
189-
// If the generic parameter list has inherited requirements attached
190-
// directly to the parameters themselves, leave them in place.
191-
auto InheritedGenericConstraints = LastGenericParam->getInherited();
192-
if (!InheritedGenericConstraints.empty()) {
193-
EndOfLastGenericParam =
194-
Lexer::getLocForEndOfToken(SourceMgr,
195-
InheritedGenericConstraints.back().getLoc());
196-
}
186+
Lexer::getLocForEndOfToken(SourceMgr, LastGenericParam->getEndLoc());
197187

198188
CharSourceRange RemoveWhereRange { SourceMgr,
199189
EndOfLastGenericParam,
@@ -218,17 +208,14 @@ Parser::diagnoseWhereClauseInGenericParamList(const GenericParamList *
218208

219209
auto Diag = diagnose(WhereRangeInsideBrackets.Start,
220210
diag::where_inside_brackets);
211+
Diag.fixItRemoveChars(RemoveWhereRange.getStart(),
212+
RemoveWhereRange.getEnd());
221213

222214
if (Tok.is(tok::kw_where)) {
223-
Diag.fixItRemoveChars(RemoveWhereRange.getStart(),
224-
RemoveWhereRange.getEnd())
225-
.fixItReplace(Tok.getLoc(),
226-
WhereClauseText.str());
215+
Diag.fixItReplace(Tok.getLoc(), WhereClauseText.str());
227216
} else {
228-
Diag.fixItRemoveChars(RemoveWhereRange.getStart(),
229-
RemoveWhereRange.getEnd())
230-
.fixItInsert(Lexer::getLocForEndOfToken(SourceMgr, PreviousLoc),
231-
WhereClauseText.str());
217+
Diag.fixItInsert(Lexer::getLocForEndOfToken(SourceMgr, PreviousLoc),
218+
WhereClauseText.str());
232219
}
233220
}
234221

test/Parse/deprecated_where.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,16 @@ struct S23<T where T: Comparable> where T: Equatable {} // expected-warning {{'w
6464
// 1,2,3
6565
struct S123<T: Hashable where T: Comparable> where T: Equatable {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{24-44=}} {{46-51=where T: Comparable,}}
6666

67+
68+
protocol ProtoA {}
69+
protocol ProtoB {}
70+
protocol ProtoC {}
71+
protocol ProtoD {}
72+
func testCombinedConstraints<T: ProtoA & ProtoB where T: ProtoC>(x: T) {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{48-64=}} {{71-71= where T: ProtoC}}
73+
func testCombinedConstraints<T: ProtoA & ProtoB where T: ProtoC>(x: T) where T: ProtoD {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{48-64=}} {{72-77=where T: ProtoC,}}
74+
75+
func testCombinedConstraintsOld<T: protocol<ProtoA, ProtoB> where T: ProtoC>(x: T) {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{60-76=}} {{83-83= where T: ProtoC}}
76+
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
77+
func testCombinedConstraintsOld<T: protocol<ProtoA, ProtoB> where T: ProtoC>(x: T) where T: ProtoD {} // expected-warning {{'where' clause next to generic parameters is deprecated and will be removed in the future version of Swift}} {{60-76=}} {{84-89=where T: ProtoC,}}
78+
// expected-warning@-1 {{'protocol<...>' composition syntax is deprecated}}
79+

0 commit comments

Comments
 (0)