Skip to content

Commit 379d88c

Browse files
authored
Merge pull request #25575 from xedin/rdar-51784793
[Diagnostics] Guard against missing parent initializer in missing unw…
2 parents e52feac + fca8106 commit 379d88c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -901,9 +901,10 @@ bool MemberAccessOnOptionalBaseFailure::diagnoseAsError() {
901901

902902
void MissingOptionalUnwrapFailure::offerDefaultValueUnwrapFixIt(
903903
DeclContext *DC, Expr *expr) const {
904-
auto *anchor = getAnchor();
904+
assert(expr);
905905

906-
// If anchor is an explicit address-of, or expression which produces
906+
auto *anchor = getAnchor();
907+
// If anchor is n explicit address-of, or expression which produces
907908
// an l-value (e.g. first argument of `+=` operator), let's not
908909
// suggest default value here because that would produce r-value type.
909910
if (isa<InOutExpr>(anchor))
@@ -1047,7 +1048,10 @@ bool MissingOptionalUnwrapFailure::diagnoseAsError() {
10471048
if (singleUse && binding && binding->getNumPatternEntries() == 1 &&
10481049
varDecl->getTypeSourceRangeForDiagnostics().isInvalid()) {
10491050

1050-
Expr *initializer = varDecl->getParentInitializer();
1051+
auto *initializer = varDecl->getParentInitializer();
1052+
if (!initializer)
1053+
return true;
1054+
10511055
if (auto declRefExpr = dyn_cast<DeclRefExpr>(initializer)) {
10521056
if (declRefExpr->getDecl()
10531057
->getAttrs()

0 commit comments

Comments
 (0)