Skip to content

Commit ef5e286

Browse files
committed
Sema: Fix crash on invalid code in diagnoseDictionaryLiteralDuplicateKeyEntries()
1 parent 8b12f8c commit ef5e286

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6268,9 +6268,9 @@ diagnoseDictionaryLiteralDuplicateKeyEntries(const Expr *E,
62686268
note.fixItRemove(duplicated.first->getSourceRange());
62696269
if (duplicatedEltIdx < commanLocs.size()) {
62706270
note.fixItRemove(commanLocs[duplicatedEltIdx]);
6271-
} else {
6271+
} else if (!commanLocs.empty()) {
62726272
// For the last element remove the previous comma.
6273-
note.fixItRemove(commanLocs[duplicatedEltIdx - 1]);
6273+
note.fixItRemove(commanLocs[commanLocs.size() - 1]);
62746274
}
62756275
};
62766276

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"diagnoseDictionaryLiteralDuplicateKeyEntries(swift::Expr const*, swift::DeclContext const*)::DiagnoseWalker::walkToExprPre(swift::Expr*)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
[ 1.01: "" 1.01: ""

0 commit comments

Comments
 (0)