Skip to content

Commit 1ca799b

Browse files
committed
[code-completion] Fix crash in typeCheckConstructorBodyUntil with null nominal context
With erroneous code, such as in code-completion, it's not safe to assume that the constructor is inside a nominal decl context. rdar://problem/28867794
1 parent d822c39 commit 1ca799b

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ bool TypeChecker::typeCheckConstructorBodyUntil(ConstructorDecl *ctor,
14031403
// Determine whether we need to introduce a super.init call.
14041404
auto nominalDecl = ctor->getDeclContext()
14051405
->getAsNominalTypeOrNominalTypeExtensionContext();
1406-
ClassDecl *ClassD = dyn_cast<ClassDecl>(nominalDecl);
1406+
ClassDecl *ClassD = dyn_cast_or_null<ClassDecl>(nominalDecl);
14071407
bool wantSuperInitCall = false;
14081408
if (ClassD) {
14091409
bool isDelegating = false;

validation-test/IDE/crashers/040-swift-typechecker-typecheckconstructorbodyuntil.swift

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
t{extension{init(){#^A^#

0 commit comments

Comments
 (0)