Skip to content

Commit 6130175

Browse files
authored
Merge pull request #19375 from slavapestov/subscript-labels-crash
Sema: Fix crash when overriding subscript with mismatched labels
2 parents c460ee9 + eff2017 commit 6130175

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ static void diagnoseGeneralOverrideFailure(ValueDecl *decl,
481481
matchDecl->getDescriptiveKind(),
482482
matchDecl->getFullName());
483483
if (attempt == OverrideCheckingAttempt::BaseName) {
484-
fixDeclarationName(diag, cast<AbstractFunctionDecl>(decl),
485-
matchDecl->getFullName());
484+
fixDeclarationName(diag, decl, matchDecl->getFullName());
486485
}
487486
}
488487
}
@@ -773,8 +772,7 @@ bool OverrideMatcher::checkOverride(ValueDecl *baseDecl,
773772
isa<ConstructorDecl>(decl),
774773
decl->getFullName(),
775774
baseDecl->getFullName());
776-
fixDeclarationName(diag, cast<AbstractFunctionDecl>(decl),
777-
baseDecl->getFullName());
775+
fixDeclarationName(diag, decl, baseDecl->getFullName());
778776
emittedMatchError = true;
779777
}
780778

test/decl/class/override.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ class Derived24646184 : Base24646184 {
277277
}
278278

279279

280+
// Subscripts
281+
282+
class SubscriptBase {
283+
subscript(a a: Int) -> Int { return a }
284+
}
285+
286+
class SubscriptDerived : SubscriptBase {
287+
override subscript(a: Int) -> Int { return a }
288+
// expected-error@-1 {{argument labels for method 'subscript' do not match those of overridden method 'subscript(a:)'}}
289+
}
290+
280291
// Generic subscripts
281292

282293
class GenericSubscriptBase {

0 commit comments

Comments
 (0)