Skip to content

Commit a21f323

Browse files
authored
Merge pull request swiftlang#36946 from xedin/rdar-61749633
[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …
2 parents 7377fff + 593bbab commit a21f323

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,24 @@ namespace {
10611061
}
10621062

10631063
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
1064-
// If this is a call, record the argument expression.
1065-
if (auto call = dyn_cast<ApplyExpr>(expr)) {
1066-
if (!isa<SelfApplyExpr>(expr)) {
1067-
CallArgs.insert(call->getArg());
1064+
// If this is a call or subscript, record the argument expression.
1065+
{
1066+
if (auto call = dyn_cast<ApplyExpr>(expr)) {
1067+
if (!isa<SelfApplyExpr>(expr)) {
1068+
CallArgs.insert(call->getArg());
1069+
}
1070+
}
1071+
1072+
if (auto *subscript = dyn_cast<SubscriptExpr>(expr)) {
1073+
CallArgs.insert(subscript->getIndex());
1074+
}
1075+
1076+
if (auto *dynamicSubscript = dyn_cast<DynamicSubscriptExpr>(expr)) {
1077+
CallArgs.insert(dynamicSubscript->getIndex());
1078+
}
1079+
1080+
if (auto *OLE = dyn_cast<ObjectLiteralExpr>(expr)) {
1081+
CallArgs.insert(OLE->getArg());
10681082
}
10691083
}
10701084

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -typecheck
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
_ = Dictionary[String: Any]()
7+
8+
func test(obj: AnyObject) {
9+
obj[String: Any] // Dynamic subscript
10+
}
11+
12+
#colorLiteral(String: Any)

validation-test/compiler_crashers_2_fixed/sr12990.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ContainerTransition {
55
func completeTransition() {
66
viewControllers?[Int//.max
77
// 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>>')}}
8+
// expected-note@-2 {{found candidate with type '(Int.Type) -> Dictionary<Int, String>.SubSequence' (aka '(Int.Type) -> Slice<Dictionary<Int, String>>')}}
99
// expected-note@-3 {{to match this opening '['}}
1010
} // expected-error {{expected ']' in expression list}}
1111
}

0 commit comments

Comments
 (0)