Skip to content

Commit 594b12a

Browse files
authored
Merge pull request #14107 from akyrtzi/fix-crash-invalid-entity-walker-5.0
[5.0][AST] Make sure that if a TupleExpr is created with element names but not name locations, it is marked implicit as appropriate
2 parents 6783d24 + 11e0d1f commit 594b12a

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
@@ -1921,6 +1921,11 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
19211921
}
19221922
void visitDictionaryExpr(DictionaryExpr *E) {
19231923
printCommon(E, "dictionary_expr");
1924+
if (auto semaE = E->getSemanticExpr()) {
1925+
OS << '\n';
1926+
printRec(semaE);
1927+
return;
1928+
}
19241929
for (auto elt : E->getElements()) {
19251930
OS << '\n';
19261931
printRec(elt);

lib/AST/Expr.cpp

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

12001200
auto arg = TupleExpr::create(ctx, lParenLoc, args, argLabels, argLabelLocs,
12011201
rParenLoc, /*HasTrailingClosure=*/false,
1202-
/*Implicit=*/false);
1202+
implicit);
12031203
computeSingleArgumentType(ctx, arg, implicit, getType);
12041204
return arg;
12051205
}
@@ -1498,6 +1498,16 @@ TupleExpr *TupleExpr::create(ASTContext &ctx,
14981498
SourceLoc RParenLoc, bool HasTrailingClosure,
14991499
bool Implicit, Type Ty) {
15001500
assert(!Ty || isa<TupleType>(Ty.getPointer()));
1501+
auto hasNonEmptyIdentifier = [](ArrayRef<Identifier> Ids) -> bool {
1502+
for (auto ident : Ids) {
1503+
if (!ident.empty())
1504+
return true;
1505+
}
1506+
return false;
1507+
};
1508+
assert((Implicit || ElementNames.size() == ElementNameLocs.size() ||
1509+
(!hasNonEmptyIdentifier(ElementNames) && ElementNameLocs.empty())) &&
1510+
"trying to create non-implicit tuple-expr without name locations");
15011511

15021512
size_t size =
15031513
totalSizeToAlloc<Expr *, Identifier, SourceLoc>(SubExprs.size(),

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@ namespace {
29142914
{ },
29152915
expr->getRBracketLoc(),
29162916
/*HasTrailingClosure=*/false,
2917-
/*Implicit=*/false,
2917+
/*Implicit=*/true,
29182918
argType);
29192919

29202920
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)