@@ -3268,8 +3268,6 @@ namespace {
3268
3268
auto type = simplifyType (openedType);
3269
3269
cs.setType (expr, type);
3270
3270
3271
- assert (!type->is <UnresolvedType>());
3272
-
3273
3271
Type conformingType = type;
3274
3272
if (auto baseType = conformingType->getOptionalObjectType ()) {
3275
3273
// The type may be optional due to a failable initializer in the
@@ -3461,10 +3459,6 @@ namespace {
3461
3459
// an ambiguity tolerant mode used for diagnostic generation. Just leave
3462
3460
// this as an unresolved member reference.
3463
3461
Type resultTy = simplifyType (cs.getType (expr));
3464
- if (resultTy->hasUnresolvedType ()) {
3465
- cs.setType (expr, resultTy);
3466
- return expr;
3467
- }
3468
3462
3469
3463
// Find the selected member and base type.
3470
3464
auto memberLocator = cs.getConstraintLocator (
@@ -4935,7 +4929,6 @@ namespace {
4935
4929
Expr *visitEditorPlaceholderExpr (EditorPlaceholderExpr *E) {
4936
4930
simplifyExprType (E);
4937
4931
auto valueType = cs.getType (E);
4938
- assert (!valueType->hasUnresolvedType ());
4939
4932
4940
4933
// Synthesize a call to _undefined() of appropriate type.
4941
4934
FuncDecl *undefinedDecl = ctx.getUndefined ();
@@ -5264,13 +5257,6 @@ namespace {
5264
5257
auto componentTy = baseTy;
5265
5258
for (unsigned i : indices (E->getComponents ())) {
5266
5259
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
- }
5274
5260
5275
5261
auto kind = origComponent.getKind ();
5276
5262
auto componentLocator =
@@ -5325,7 +5311,6 @@ namespace {
5325
5311
case KeyPathExpr::Component::Kind::OptionalChain: {
5326
5312
didOptionalChain = true ;
5327
5313
// Chaining always forces the element to be an rvalue.
5328
- assert (!componentTy->hasUnresolvedType ());
5329
5314
auto objectTy =
5330
5315
componentTy->getWithoutSpecifierType ()->getOptionalObjectType ();
5331
5316
assert (objectTy);
@@ -5377,8 +5362,7 @@ namespace {
5377
5362
}
5378
5363
5379
5364
// Wrap a non-optional result if there was chaining involved.
5380
- assert (!componentTy->hasUnresolvedType ());
5381
- if (didOptionalChain && componentTy &&
5365
+ if (didOptionalChain &&
5382
5366
!componentTy->getWithoutSpecifierType ()->isEqual (leafTy)) {
5383
5367
auto component = KeyPathExpr::Component::forOptionalWrap (leafTy);
5384
5368
resolvedComponents.push_back (component);
@@ -5504,7 +5488,6 @@ namespace {
5504
5488
5505
5489
// Unwrap the last component type, preserving @lvalue-ness.
5506
5490
auto optionalTy = components.back ().getComponentType ();
5507
- assert (!optionalTy->hasUnresolvedType ());
5508
5491
Type objectTy;
5509
5492
if (auto lvalue = optionalTy->getAs <LValueType>()) {
5510
5493
objectTy = lvalue->getObjectType ()->getOptionalObjectType ();
@@ -7218,6 +7201,9 @@ Expr *ConstraintSystem::addImplicitLoadExpr(Expr *expr) {
7218
7201
7219
7202
Expr *ExprRewriter::coerceToType (Expr *expr, Type toType,
7220
7203
ConstraintLocatorBuilder locator) {
7204
+ ASSERT (toType && !toType->hasError () && !toType->hasUnresolvedType () &&
7205
+ !toType->hasTypeVariableOrPlaceholder ());
7206
+
7221
7207
// Diagnose conversions to invalid function types that couldn't be performed
7222
7208
// beforehand because of placeholders.
7223
7209
if (auto *fnTy = toType->getAs <FunctionType>()) {
@@ -7245,8 +7231,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
7245
7231
if (knownRestriction != solution.ConstraintRestrictions .end ()) {
7246
7232
switch (knownRestriction->second ) {
7247
7233
case ConversionRestrictionKind::DeepEquality: {
7248
- assert (!toType->hasUnresolvedType ());
7249
-
7250
7234
// HACK: Fix problem related to Swift 4 mode (with assertions),
7251
7235
// since Swift 4 mode allows passing arguments with extra parens
7252
7236
// to parameters which don't expect them, it should be supported
@@ -8119,9 +8103,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
8119
8103
}
8120
8104
}
8121
8105
8122
- assert (!fromType->hasUnresolvedType ());
8123
- assert (!toType->hasUnresolvedType ());
8124
-
8125
8106
ABORT ([&](auto &out) {
8126
8107
out << " Unhandled coercion:\n " ;
8127
8108
fromType->dump (out);
@@ -8224,13 +8205,6 @@ Expr *ExprRewriter::convertLiteralInPlace(
8224
8205
Identifier literalType, DeclName literalFuncName,
8225
8206
ProtocolDecl *builtinProtocol, DeclName builtinLiteralFuncName,
8226
8207
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
-
8234
8208
// Check whether this literal type conforms to the builtin protocol. If so,
8235
8209
// initialize via the builtin protocol.
8236
8210
if (builtinProtocol) {
@@ -8669,8 +8643,6 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
8669
8643
8670
8644
// FIXME: Handle unwrapping everywhere else.
8671
8645
8672
- assert (!cs.getType (fn)->is <UnresolvedType>());
8673
-
8674
8646
// We have a type constructor.
8675
8647
auto metaTy = cs.getType (fn)->castTo <AnyMetatypeType>();
8676
8648
auto ty = metaTy->getInstanceType ();
@@ -10036,6 +10008,26 @@ ConstraintSystem::applySolution(Solution &solution,
10036
10008
}
10037
10009
}
10038
10010
10011
+ // If the score indicates the solution is valid, ensure we don't have any
10012
+ // unresolved types.
10013
+ {
10014
+ auto isValidType = [&](Type ty) {
10015
+ return !ty->hasUnresolvedType () && !ty->hasError () &&
10016
+ !ty->hasTypeVariableOrPlaceholder ();
10017
+ };
10018
+ for (auto &[_, type] : solution.typeBindings ) {
10019
+ ASSERT (isValidType (type) && " type binding has invalid type" );
10020
+ }
10021
+ for (auto &[_, type] : solution.nodeTypes ) {
10022
+ ASSERT (isValidType (solution.simplifyType (type)) &&
10023
+ " node type has invalid type" );
10024
+ }
10025
+ for (auto &[_, type] : solution.keyPathComponentTypes ) {
10026
+ ASSERT (isValidType (solution.simplifyType (type)) &&
10027
+ " key path type has invalid type" );
10028
+ }
10029
+ }
10030
+
10039
10031
ExprRewriter rewriter (*this , solution, target, shouldSuppressDiagnostics ());
10040
10032
ExprWalker walker (rewriter);
10041
10033
auto resultTarget = walker.rewriteTarget (target);
0 commit comments