@@ -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
@@ -3457,14 +3455,7 @@ namespace {
3457
3455
}
3458
3456
3459
3457
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.
3463
3458
Type resultTy = simplifyType (cs.getType (expr));
3464
- if (resultTy->hasUnresolvedType ()) {
3465
- cs.setType (expr, resultTy);
3466
- return expr;
3467
- }
3468
3459
3469
3460
// Find the selected member and base type.
3470
3461
auto memberLocator = cs.getConstraintLocator (
@@ -4935,7 +4926,6 @@ namespace {
4935
4926
Expr *visitEditorPlaceholderExpr (EditorPlaceholderExpr *E) {
4936
4927
simplifyExprType (E);
4937
4928
auto valueType = cs.getType (E);
4938
- assert (!valueType->hasUnresolvedType ());
4939
4929
4940
4930
// Synthesize a call to _undefined() of appropriate type.
4941
4931
FuncDecl *undefinedDecl = ctx.getUndefined ();
@@ -5264,13 +5254,6 @@ namespace {
5264
5254
auto componentTy = baseTy;
5265
5255
for (unsigned i : indices (E->getComponents ())) {
5266
5256
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
5257
5275
5258
auto kind = origComponent.getKind ();
5276
5259
auto componentLocator =
@@ -5325,7 +5308,6 @@ namespace {
5325
5308
case KeyPathExpr::Component::Kind::OptionalChain: {
5326
5309
didOptionalChain = true ;
5327
5310
// Chaining always forces the element to be an rvalue.
5328
- assert (!componentTy->hasUnresolvedType ());
5329
5311
auto objectTy =
5330
5312
componentTy->getWithoutSpecifierType ()->getOptionalObjectType ();
5331
5313
assert (objectTy);
@@ -5377,8 +5359,7 @@ namespace {
5377
5359
}
5378
5360
5379
5361
// Wrap a non-optional result if there was chaining involved.
5380
- assert (!componentTy->hasUnresolvedType ());
5381
- if (didOptionalChain && componentTy &&
5362
+ if (didOptionalChain &&
5382
5363
!componentTy->getWithoutSpecifierType ()->isEqual (leafTy)) {
5383
5364
auto component = KeyPathExpr::Component::forOptionalWrap (leafTy);
5384
5365
resolvedComponents.push_back (component);
@@ -5504,7 +5485,6 @@ namespace {
5504
5485
5505
5486
// Unwrap the last component type, preserving @lvalue-ness.
5506
5487
auto optionalTy = components.back ().getComponentType ();
5507
- assert (!optionalTy->hasUnresolvedType ());
5508
5488
Type objectTy;
5509
5489
if (auto lvalue = optionalTy->getAs <LValueType>()) {
5510
5490
objectTy = lvalue->getObjectType ()->getOptionalObjectType ();
@@ -7218,6 +7198,9 @@ Expr *ConstraintSystem::addImplicitLoadExpr(Expr *expr) {
7218
7198
7219
7199
Expr *ExprRewriter::coerceToType (Expr *expr, Type toType,
7220
7200
ConstraintLocatorBuilder locator) {
7201
+ ASSERT (toType && !toType->hasError () && !toType->hasUnresolvedType () &&
7202
+ !toType->hasTypeVariableOrPlaceholder ());
7203
+
7221
7204
// Diagnose conversions to invalid function types that couldn't be performed
7222
7205
// beforehand because of placeholders.
7223
7206
if (auto *fnTy = toType->getAs <FunctionType>()) {
@@ -7245,8 +7228,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
7245
7228
if (knownRestriction != solution.ConstraintRestrictions .end ()) {
7246
7229
switch (knownRestriction->second ) {
7247
7230
case ConversionRestrictionKind::DeepEquality: {
7248
- assert (!toType->hasUnresolvedType ());
7249
-
7250
7231
// HACK: Fix problem related to Swift 4 mode (with assertions),
7251
7232
// since Swift 4 mode allows passing arguments with extra parens
7252
7233
// to parameters which don't expect them, it should be supported
@@ -8119,9 +8100,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
8119
8100
}
8120
8101
}
8121
8102
8122
- assert (!fromType->hasUnresolvedType ());
8123
- assert (!toType->hasUnresolvedType ());
8124
-
8125
8103
ABORT ([&](auto &out) {
8126
8104
out << " Unhandled coercion:\n " ;
8127
8105
fromType->dump (out);
@@ -8224,13 +8202,6 @@ Expr *ExprRewriter::convertLiteralInPlace(
8224
8202
Identifier literalType, DeclName literalFuncName,
8225
8203
ProtocolDecl *builtinProtocol, DeclName builtinLiteralFuncName,
8226
8204
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
8205
// Check whether this literal type conforms to the builtin protocol. If so,
8235
8206
// initialize via the builtin protocol.
8236
8207
if (builtinProtocol) {
@@ -8669,8 +8640,6 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
8669
8640
8670
8641
// FIXME: Handle unwrapping everywhere else.
8671
8642
8672
- assert (!cs.getType (fn)->is <UnresolvedType>());
8673
-
8674
8643
// We have a type constructor.
8675
8644
auto metaTy = cs.getType (fn)->castTo <AnyMetatypeType>();
8676
8645
auto ty = metaTy->getInstanceType ();
@@ -10036,6 +10005,26 @@ ConstraintSystem::applySolution(Solution &solution,
10036
10005
}
10037
10006
}
10038
10007
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
+
10039
10028
ExprRewriter rewriter (*this , solution, target, shouldSuppressDiagnostics ());
10040
10029
ExprWalker walker (rewriter);
10041
10030
auto resultTarget = walker.rewriteTarget (target);
0 commit comments