Skip to content

Commit 53d3141

Browse files
committed
[AST] Make sure that if a TupleExpr is created with element names but not name locations, it is marked implicit as appropriate
Fixes a crash for SourceEntityWalker which assumed that a non-implicit TupleExpr has source locations for its name elements. Fixes SR-6517, rdar://35830880
1 parent 8a65800 commit 53d3141

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,11 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
19171917
}
19181918
void visitDictionaryExpr(DictionaryExpr *E) {
19191919
printCommon(E, "dictionary_expr");
1920+
if (auto semaE = E->getSemanticExpr()) {
1921+
OS << '\n';
1922+
printRec(semaE);
1923+
return;
1924+
}
19201925
for (auto elt : E->getElements()) {
19211926
OS << '\n';
19221927
printRec(elt);

lib/AST/Expr.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc, ArrayRef<Expr *> args,
11971197

11981198
auto arg = TupleExpr::create(ctx, lParenLoc, args, argLabels, argLabelLocs,
11991199
rParenLoc, /*HasTrailingClosure=*/false,
1200-
/*Implicit=*/false);
1200+
implicit);
12011201
computeSingleArgumentType(ctx, arg, implicit, getType);
12021202
return arg;
12031203
}
@@ -1454,6 +1454,16 @@ TupleExpr *TupleExpr::create(ASTContext &ctx,
14541454
SourceLoc RParenLoc, bool HasTrailingClosure,
14551455
bool Implicit, Type Ty) {
14561456
assert(!Ty || isa<TupleType>(Ty.getPointer()));
1457+
auto hasNonEmptyIdentifier = [](ArrayRef<Identifier> Ids) -> bool {
1458+
for (auto ident : Ids) {
1459+
if (!ident.empty())
1460+
return true;
1461+
}
1462+
return false;
1463+
};
1464+
assert((Implicit || ElementNames.size() == ElementNameLocs.size() ||
1465+
(!hasNonEmptyIdentifier(ElementNames) && ElementNameLocs.empty())) &&
1466+
"trying to create non-implicit tuple-expr without name locations");
14571467

14581468
size_t size =
14591469
totalSizeToAlloc<Expr *, Identifier, SourceLoc>(SubExprs.size(),

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2829,7 +2829,7 @@ namespace {
28292829
{ },
28302830
expr->getRBracketLoc(),
28312831
/*HasTrailingClosure=*/false,
2832-
/*Implicit=*/false,
2832+
/*Implicit=*/true,
28332833
argType);
28342834

28352835
cs.cacheExprTypes(arg);

test/Index/invalid_code.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@
22

33
// CHECK: [[@LINE+1]]:8 | struct/Swift | Int | {{.*}} | Ref | rel: 0
44
var _: Int { get { return 1 } }
5+
6+
class CrashTest {
7+
var something = 0
8+
func returnSelf(_ h: [AnyHashable: Any?]) -> CrashTest {
9+
return self
10+
}
11+
init() { }
12+
}
13+
// CHECK: [[@LINE+1]]:13 | instance-method/Swift | returnSelf
14+
CrashTest().returnSelf(["": 0]).something()

0 commit comments

Comments
 (0)