Skip to content

Commit e5becab

Browse files
committed
Sema: Fix crashes when applying solution with error types or unresolved types
1 parent 4b49b66 commit e5becab

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

lib/Sema/CSApply.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7085,12 +7085,6 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
70857085
auto metaTy = cs.getType(fn)->castTo<AnyMetatypeType>();
70867086
auto ty = metaTy->getInstanceType();
70877087

7088-
// If this is an UnresolvedType in the system, preserve it.
7089-
if (ty->is<UnresolvedType>()) {
7090-
cs.setType(apply, ty);
7091-
return apply;
7092-
}
7093-
70947088
if (!cs.isTypeReference(fn)) {
70957089
bool isExistentialType = false;
70967090
// If this is an attempt to initialize existential type.
@@ -7117,12 +7111,18 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
71177111

71187112
// We're constructing a value of nominal type. Look for the constructor or
71197113
// enum element to use.
7120-
assert(ty->getNominalOrBoundGenericNominal() || ty->is<DynamicSelfType>() ||
7121-
ty->isExistentialType() || ty->is<ArchetypeType>());
71227114
auto ctorLocator = cs.getConstraintLocator(
71237115
locator.withPathElement(ConstraintLocator::ApplyFunction)
71247116
.withPathElement(ConstraintLocator::ConstructorMember));
71257117
auto selected = getOverloadChoiceIfAvailable(ctorLocator);
7118+
if (!selected) {
7119+
assert(ty->hasError() || ty->hasUnresolvedType());
7120+
cs.setType(apply, ty);
7121+
return apply;
7122+
}
7123+
7124+
assert(ty->getNominalOrBoundGenericNominal() || ty->is<DynamicSelfType>() ||
7125+
ty->isExistentialType() || ty->is<ArchetypeType>());
71267126

71277127
// We have the constructor.
71287128
auto choice = selected->choice;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
&{LazyFilterIndex{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
@objc protocol P{struct B{var f=_=a{}}class a{}typealias a

0 commit comments

Comments
 (0)