Skip to content

Commit ddf49af

Browse files
committed
Handle invalid contexts when computing the super type.
1 parent a33e608 commit ddf49af

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,9 +2553,14 @@ namespace {
25532553
Diag<> diag_no_base_class) {
25542554
DeclContext *typeContext = selfDecl->getDeclContext()->getParent();
25552555
assert(typeContext && "constructor without parent context?!");
2556+
2557+
// A DC can fail to have a declared type in context when it's invalid.
2558+
Type declaredType = typeContext->getDeclaredTypeInContext();
2559+
if (!declaredType)
2560+
return Type();
2561+
25562562
auto &tc = CS.getTypeChecker();
2557-
ClassDecl *classDecl = typeContext->getDeclaredTypeInContext()
2558-
->getClassOrBoundGenericClass();
2563+
ClassDecl *classDecl = declaredType->getClassOrBoundGenericClass();
25592564
if (!classDecl) {
25602565
tc.diagnose(diagLoc, diag_not_in_class);
25612566
return Type();
@@ -2565,8 +2570,7 @@ namespace {
25652570
return Type();
25662571
}
25672572

2568-
Type superclassTy = typeContext->getDeclaredTypeInContext()
2569-
->getSuperclass(&tc);
2573+
Type superclassTy = declaredType->getSuperclass(&tc);
25702574
if (selfDecl->hasType() && selfDecl->getType()->is<AnyMetatypeType>())
25712575
superclassTy = MetatypeType::get(superclassTy);
25722576
return superclassTy;

validation-test/compiler_crashers/28325-swift-typebase-getcanonicaltype.swift renamed to validation-test/compiler_crashers_fixed/28325-swift-typebase-getcanonicaltype.swift

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

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
{extension{let h{B{}{var _=super.i

0 commit comments

Comments
 (0)