Skip to content

Commit a870bdb

Browse files
committed
Fix for crash 28328. A decl's computeNominalType() can return null, but a bunch of places expect getDeclaredTypeInContext() to never be null so use ErrorType instead.
1 parent fe98a0d commit a870bdb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,8 +1995,10 @@ Type NominalTypeDecl::getDeclaredTypeInContext() const {
19951995
return DeclaredTyInContext;
19961996

19971997
auto *decl = const_cast<NominalTypeDecl *>(this);
1998-
decl->DeclaredTyInContext =
1999-
computeNominalType(decl, DeclTypeKind::DeclaredTypeInContext);
1998+
auto Ty = computeNominalType(decl, DeclTypeKind::DeclaredTypeInContext);
1999+
if (!Ty)
2000+
Ty = ErrorType::get(getASTContext());
2001+
decl->DeclaredTyInContext = Ty;
20002002
return DeclaredTyInContext;
20012003
}
20022004

validation-test/compiler_crashers/28328-swift-typebase-getdesugaredtype.swift renamed to validation-test/compiler_crashers_fixed/28328-swift-typebase-getdesugaredtype.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
let a{extension{enum k:String{{{}}case

0 commit comments

Comments
 (0)