Skip to content

Commit 6d5e482

Browse files
authored
Merge pull request #6844 from rintaro/crasher-crasher-28602
[Diag] Don't attempt 'fixOverrideDeclarationTypes' when indices count doesn't match for subscript
2 parents 8673a60 + 3952e00 commit 6d5e482

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,11 +1830,14 @@ bool swift::fixItOverrideDeclarationTypes(InFlightDiagnostic &diag,
18301830
if (auto *subscript = dyn_cast<SubscriptDecl>(decl)) {
18311831
auto *baseSubscript = cast<SubscriptDecl>(base);
18321832
bool fixedAny = false;
1833-
for_each(*subscript->getIndices(),
1834-
*baseSubscript->getIndices(),
1835-
[&](ParamDecl *param, const ParamDecl *baseParam) {
1836-
fixedAny |= fixItOverrideDeclarationTypes(diag, param, baseParam);
1837-
});
1833+
if (subscript->getIndices()->size() ==
1834+
baseSubscript->getIndices()->size()) {
1835+
for_each(*subscript->getIndices(),
1836+
*baseSubscript->getIndices(),
1837+
[&](ParamDecl *param, const ParamDecl *baseParam) {
1838+
fixedAny |= fixItOverrideDeclarationTypes(diag, param, baseParam);
1839+
});
1840+
}
18381841

18391842
auto resultType = subscript->getDeclContext()->mapTypeIntoContext(
18401843
subscript->getElementInterfaceType());

validation-test/compiler_crashers/28602-c1-size-c2-size.swift renamed to validation-test/compiler_crashers_fixed/28602-c1-size-c2-size.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9-
// REQUIRES: asserts
8+
// RUN: not %target-swift-frontend %s -emit-ir
109
protocol a{subscript->a}class c)extension c:a{subscript(b:a)->a

0 commit comments

Comments
 (0)