@@ -3268,8 +3268,6 @@ namespace {
32683268 auto type = simplifyType (openedType);
32693269 cs.setType (expr, type);
32703270
3271- assert (!type->is <UnresolvedType>());
3272-
32733271 Type conformingType = type;
32743272 if (auto baseType = conformingType->getOptionalObjectType ()) {
32753273 // The type may be optional due to a failable initializer in the
@@ -3457,14 +3455,7 @@ namespace {
34573455 }
34583456
34593457 Expr *visitUnresolvedMemberExpr (UnresolvedMemberExpr *expr) {
3460- // If constraint solving resolved this to an UnresolvedType, then we're in
3461- // an ambiguity tolerant mode used for diagnostic generation. Just leave
3462- // this as an unresolved member reference.
34633458 Type resultTy = simplifyType (cs.getType (expr));
3464- if (resultTy->hasUnresolvedType ()) {
3465- cs.setType (expr, resultTy);
3466- return expr;
3467- }
34683459
34693460 // Find the selected member and base type.
34703461 auto memberLocator = cs.getConstraintLocator (
@@ -4935,7 +4926,6 @@ namespace {
49354926 Expr *visitEditorPlaceholderExpr (EditorPlaceholderExpr *E) {
49364927 simplifyExprType (E);
49374928 auto valueType = cs.getType (E);
4938- assert (!valueType->hasUnresolvedType ());
49394929
49404930 // Synthesize a call to _undefined() of appropriate type.
49414931 FuncDecl *undefinedDecl = ctx.getUndefined ();
@@ -5264,13 +5254,6 @@ namespace {
52645254 auto componentTy = baseTy;
52655255 for (unsigned i : indices (E->getComponents ())) {
52665256 auto &origComponent = E->getMutableComponents ()[i];
5267-
5268- // If there were unresolved types, we may end up with a null base for
5269- // following components.
5270- if (!componentTy) {
5271- resolvedComponents.push_back (origComponent);
5272- continue ;
5273- }
52745257
52755258 auto kind = origComponent.getKind ();
52765259 auto componentLocator =
@@ -5325,7 +5308,6 @@ namespace {
53255308 case KeyPathExpr::Component::Kind::OptionalChain: {
53265309 didOptionalChain = true ;
53275310 // Chaining always forces the element to be an rvalue.
5328- assert (!componentTy->hasUnresolvedType ());
53295311 auto objectTy =
53305312 componentTy->getWithoutSpecifierType ()->getOptionalObjectType ();
53315313 assert (objectTy);
@@ -5377,8 +5359,7 @@ namespace {
53775359 }
53785360
53795361 // Wrap a non-optional result if there was chaining involved.
5380- assert (!componentTy->hasUnresolvedType ());
5381- if (didOptionalChain && componentTy &&
5362+ if (didOptionalChain &&
53825363 !componentTy->getWithoutSpecifierType ()->isEqual (leafTy)) {
53835364 auto component = KeyPathExpr::Component::forOptionalWrap (leafTy);
53845365 resolvedComponents.push_back (component);
@@ -5504,7 +5485,6 @@ namespace {
55045485
55055486 // Unwrap the last component type, preserving @lvalue-ness.
55065487 auto optionalTy = components.back ().getComponentType ();
5507- assert (!optionalTy->hasUnresolvedType ());
55085488 Type objectTy;
55095489 if (auto lvalue = optionalTy->getAs <LValueType>()) {
55105490 objectTy = lvalue->getObjectType ()->getOptionalObjectType ();
@@ -7218,6 +7198,9 @@ Expr *ConstraintSystem::addImplicitLoadExpr(Expr *expr) {
72187198
72197199Expr *ExprRewriter::coerceToType (Expr *expr, Type toType,
72207200 ConstraintLocatorBuilder locator) {
7201+ ASSERT (toType && !toType->hasError () && !toType->hasUnresolvedType () &&
7202+ !toType->hasTypeVariableOrPlaceholder ());
7203+
72217204 // Diagnose conversions to invalid function types that couldn't be performed
72227205 // beforehand because of placeholders.
72237206 if (auto *fnTy = toType->getAs <FunctionType>()) {
@@ -7245,8 +7228,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
72457228 if (knownRestriction != solution.ConstraintRestrictions .end ()) {
72467229 switch (knownRestriction->second ) {
72477230 case ConversionRestrictionKind::DeepEquality: {
7248- assert (!toType->hasUnresolvedType ());
7249-
72507231 // HACK: Fix problem related to Swift 4 mode (with assertions),
72517232 // since Swift 4 mode allows passing arguments with extra parens
72527233 // to parameters which don't expect them, it should be supported
@@ -8119,9 +8100,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
81198100 }
81208101 }
81218102
8122- assert (!fromType->hasUnresolvedType ());
8123- assert (!toType->hasUnresolvedType ());
8124-
81258103 ABORT ([&](auto &out) {
81268104 out << " Unhandled coercion:\n " ;
81278105 fromType->dump (out);
@@ -8224,13 +8202,6 @@ Expr *ExprRewriter::convertLiteralInPlace(
82248202 Identifier literalType, DeclName literalFuncName,
82258203 ProtocolDecl *builtinProtocol, DeclName builtinLiteralFuncName,
82268204 Diag<> brokenProtocolDiag, Diag<> brokenBuiltinProtocolDiag) {
8227- // If coercing a literal to an unresolved type, we don't try to look up the
8228- // witness members, just do it.
8229- if (type->is <UnresolvedType>() || type->is <ErrorType>()) {
8230- cs.setType (literal, type);
8231- return literal;
8232- }
8233-
82348205 // Check whether this literal type conforms to the builtin protocol. If so,
82358206 // initialize via the builtin protocol.
82368207 if (builtinProtocol) {
@@ -8669,8 +8640,6 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
86698640
86708641 // FIXME: Handle unwrapping everywhere else.
86718642
8672- assert (!cs.getType (fn)->is <UnresolvedType>());
8673-
86748643 // We have a type constructor.
86758644 auto metaTy = cs.getType (fn)->castTo <AnyMetatypeType>();
86768645 auto ty = metaTy->getInstanceType ();
@@ -10036,6 +10005,26 @@ ConstraintSystem::applySolution(Solution &solution,
1003610005 }
1003710006 }
1003810007
10008+ // If the score indicates the solution is valid, ensure we don't have any
10009+ // unresolved types.
10010+ {
10011+ auto isValidType = [&](Type ty) {
10012+ return !ty->hasUnresolvedType () && !ty->hasError () &&
10013+ !ty->hasTypeVariableOrPlaceholder ();
10014+ };
10015+ for (auto &[_, type] : solution.typeBindings ) {
10016+ ASSERT (isValidType (type) && " type binding has invalid type" );
10017+ }
10018+ for (auto &[_, type] : solution.nodeTypes ) {
10019+ ASSERT (isValidType (solution.simplifyType (type)) &&
10020+ " node type has invalid type" );
10021+ }
10022+ for (auto &[_, type] : solution.keyPathComponentTypes ) {
10023+ ASSERT (isValidType (solution.simplifyType (type)) &&
10024+ " key path type has invalid type" );
10025+ }
10026+ }
10027+
1003910028 ExprRewriter rewriter (*this , solution, target, shouldSuppressDiagnostics ());
1004010029 ExprWalker walker (rewriter);
1004110030 auto resultTarget = walker.rewriteTarget (target);
0 commit comments