Skip to content

[4.1][AST] Make sure that if a TupleExpr is created with element names but not name locations, it is marked implicit as appropriate #13888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,11 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
}
void visitDictionaryExpr(DictionaryExpr *E) {
printCommon(E, "dictionary_expr");
if (auto semaE = E->getSemanticExpr()) {
OS << '\n';
printRec(semaE);
return;
}
for (auto elt : E->getElements()) {
OS << '\n';
printRec(elt);
Expand Down
12 changes: 11 additions & 1 deletion lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc, ArrayRef<Expr *> args,

auto arg = TupleExpr::create(ctx, lParenLoc, args, argLabels, argLabelLocs,
rParenLoc, /*HasTrailingClosure=*/false,
/*Implicit=*/false);
implicit);
computeSingleArgumentType(ctx, arg, implicit, getType);
return arg;
}
Expand Down Expand Up @@ -1454,6 +1454,16 @@ TupleExpr *TupleExpr::create(ASTContext &ctx,
SourceLoc RParenLoc, bool HasTrailingClosure,
bool Implicit, Type Ty) {
assert(!Ty || isa<TupleType>(Ty.getPointer()));
auto hasNonEmptyIdentifier = [](ArrayRef<Identifier> Ids) -> bool {
for (auto ident : Ids) {
if (!ident.empty())
return true;
}
return false;
};
assert((Implicit || ElementNames.size() == ElementNameLocs.size() ||
(!hasNonEmptyIdentifier(ElementNames) && ElementNameLocs.empty())) &&
"trying to create non-implicit tuple-expr without name locations");

size_t size =
totalSizeToAlloc<Expr *, Identifier, SourceLoc>(SubExprs.size(),
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2829,7 +2829,7 @@ namespace {
{ },
expr->getRBracketLoc(),
/*HasTrailingClosure=*/false,
/*Implicit=*/false,
/*Implicit=*/true,
argType);

cs.cacheExprTypes(arg);
Expand Down
10 changes: 10 additions & 0 deletions test/Index/invalid_code.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@

// CHECK: [[@LINE+1]]:8 | struct/Swift | Int | {{.*}} | Ref | rel: 0
var _: Int { get { return 1 } }

class CrashTest {
var something = 0
func returnSelf(_ h: [AnyHashable: Any?]) -> CrashTest {
return self
}
init() { }
}
// CHECK: [[@LINE+1]]:13 | instance-method/Swift | returnSelf
CrashTest().returnSelf(["": 0]).something()