Skip to content

Commit 1564377

Browse files
authored
[CS] Update splice logic in simplifyLocator to handle situations where the index expression isn't a tuple or paren expression (swiftlang#32356)
1 parent 318e199 commit 1564377

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,6 +3451,13 @@ void constraints::simplifyLocator(ASTNode &anchor,
34513451
if (auto subscriptExpr = getAsExpr<SubscriptExpr>(anchor)) {
34523452
anchor = subscriptExpr->getIndex();
34533453
path = path.slice(1);
3454+
3455+
// TODO: It would be better if the index expression was always wrapped
3456+
// in a ParenExpr (if there is no label).
3457+
if (!(isExpr<TupleExpr>(anchor) || isExpr<ParenExpr>(anchor)) &&
3458+
!path.empty() && path[0].is<LocatorPathElt::ApplyArgToParam>()) {
3459+
path = path.slice(1);
3460+
}
34543461
continue;
34553462
}
34563463

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-frontend -typecheck %s -verify
2+
3+
class ContainerTransition {
4+
var viewControllers: [Int: String]?
5+
func completeTransition() {
6+
viewControllers?[Int//.max
7+
// expected-error@-1 {{no exact matches in call to subscript}}
8+
// expected-note@-2 {{found candidate with type '((Int).Type) -> Dictionary<Int, String>.SubSequence' (aka '(Int.Type) -> Slice<Dictionary<Int, String>>')}}
9+
// expected-note@-3 {{to match this opening '['}}
10+
} // expected-error {{expected ']' in expression list}}
11+
}

0 commit comments

Comments
 (0)