@@ -3268,8 +3268,7 @@ namespace {
32683268 auto type = simplifyType (openedType);
32693269 cs.setType (expr, type);
32703270
3271- if (type->is <UnresolvedType>())
3272- return expr;
3271+ assert (!type->is <UnresolvedType>());
32733272
32743273 Type conformingType = type;
32753274 if (auto baseType = conformingType->getOptionalObjectType ()) {
@@ -3288,14 +3287,11 @@ namespace {
32883287
32893288 ConcreteDeclRef witness = conformance.getWitnessByName (constrName);
32903289
3291- auto selectedOverload = solution.getOverloadChoiceIfAvailable (
3290+ auto selectedOverload = solution.getOverloadChoice (
32923291 cs.getConstraintLocator (expr, ConstraintLocator::ConstructorMember));
32933292
3294- if (!selectedOverload)
3295- return nullptr ;
3296-
3297- auto fnType =
3298- simplifyType (selectedOverload->adjustedOpenedType )->castTo <FunctionType>();
3293+ auto fnType = simplifyType (selectedOverload.adjustedOpenedType )
3294+ ->castTo <FunctionType>();
32993295
33003296 auto newArgs = coerceCallArguments (
33013297 expr->getArgs (), fnType, witness, /* applyExpr=*/ nullptr ,
@@ -3628,18 +3624,8 @@ namespace {
36283624 // Determine the declaration selected for this overloaded reference.
36293625 auto memberLocator = cs.getConstraintLocator (expr,
36303626 ConstraintLocator::Member);
3631- auto selectedElt = solution.getOverloadChoiceIfAvailable (memberLocator);
3632-
3633- if (!selectedElt) {
3634- // If constraint solving resolved this to an UnresolvedType, then we're
3635- // in an ambiguity tolerant mode used for diagnostic generation. Just
3636- // leave this as whatever type of member reference it already is.
3637- Type resultTy = simplifyType (cs.getType (expr));
3638- cs.setType (expr, resultTy);
3639- return expr;
3640- }
3627+ auto selected = solution.getOverloadChoice (memberLocator);
36413628
3642- auto selected = *selectedElt;
36433629 if (!selected.choice .getBaseType ()) {
36443630 // This is one of the "outer alternatives", meaning the innermost
36453631 // methods didn't work out.
@@ -3958,39 +3944,17 @@ namespace {
39583944 Expr *visitSubscriptExpr (SubscriptExpr *expr) {
39593945 auto *memberLocator =
39603946 cs.getConstraintLocator (expr, ConstraintLocator::SubscriptMember);
3961- auto overload = solution.getOverloadChoiceIfAvailable (memberLocator);
3962-
3963- // Handles situation where there was a solution available but it didn't
3964- // have a proper overload selected from subscript call, might be because
3965- // solver was allowed to return free or unresolved types, which can
3966- // happen while running diagnostics on one of the expressions.
3967- if (!overload) {
3968- auto *base = expr->getBase ();
3969- auto &de = ctx.Diags ;
3970- auto baseType = cs.getType (base);
3971-
3972- if (auto errorType = baseType->getAs <ErrorType>()) {
3973- de.diagnose (base->getLoc (), diag::cannot_subscript_base,
3974- errorType->getOriginalType ())
3975- .highlight (base->getSourceRange ());
3976- } else {
3977- de.diagnose (base->getLoc (), diag::cannot_subscript_ambiguous_base)
3978- .highlight (base->getSourceRange ());
3979- }
3980-
3981- return nullptr ;
3982- }
3983-
3984- if (overload->choice .isKeyPathDynamicMemberLookup ()) {
3947+ auto overload = solution.getOverloadChoice (memberLocator);
3948+ if (overload.choice .isKeyPathDynamicMemberLookup ()) {
39853949 return buildDynamicMemberLookupRef (
39863950 expr, expr->getBase (), expr->getArgs ()->getStartLoc (), SourceLoc (),
3987- * overload, memberLocator);
3951+ overload, memberLocator);
39883952 }
39893953
39903954 return buildSubscript (expr->getBase (), expr->getArgs (),
39913955 cs.getConstraintLocator (expr), memberLocator,
39923956 expr->isImplicit (), expr->getAccessSemantics (),
3993- * overload);
3957+ overload);
39943958 }
39953959
39963960 // / "Finish" an array expression by filling in the semantic expression.
@@ -5321,15 +5285,8 @@ namespace {
53215285 // If this is an unresolved link, make sure we resolved it.
53225286 if (kind == KeyPathExpr::Component::Kind::UnresolvedMember ||
53235287 kind == KeyPathExpr::Component::Kind::UnresolvedSubscript) {
5324- auto foundDecl = solution.getOverloadChoiceIfAvailable (calleeLoc);
5325- if (!foundDecl) {
5326- // If we couldn't resolve the component, leave it alone.
5327- resolvedComponents.push_back (origComponent);
5328- componentTy = origComponent.getComponentType ();
5329- continue ;
5330- }
5331-
5332- isDynamicMember = foundDecl->choice .isAnyDynamicMemberLookup ();
5288+ auto foundDecl = solution.getOverloadChoice (calleeLoc);
5289+ isDynamicMember = foundDecl.choice .isAnyDynamicMemberLookup ();
53335290
53345291 // If this was a @dynamicMemberLookup property, then we actually
53355292 // form a subscript reference, so switch the kind.
@@ -5368,11 +5325,9 @@ namespace {
53685325 case KeyPathExpr::Component::Kind::OptionalChain: {
53695326 didOptionalChain = true ;
53705327 // Chaining always forces the element to be an rvalue.
5328+ assert (!componentTy->hasUnresolvedType ());
53715329 auto objectTy =
53725330 componentTy->getWithoutSpecifierType ()->getOptionalObjectType ();
5373- if (componentTy->hasUnresolvedType () && !objectTy) {
5374- objectTy = componentTy;
5375- }
53765331 assert (objectTy);
53775332
53785333 auto loc = origComponent.getLoc ();
@@ -5422,8 +5377,8 @@ namespace {
54225377 }
54235378
54245379 // Wrap a non-optional result if there was chaining involved.
5380+ assert (!componentTy->hasUnresolvedType ());
54255381 if (didOptionalChain && componentTy &&
5426- !componentTy->hasUnresolvedType () &&
54275382 !componentTy->getWithoutSpecifierType ()->isEqual (leafTy)) {
54285383 auto component = KeyPathExpr::Component::forOptionalWrap (leafTy);
54295384 resolvedComponents.push_back (component);
@@ -5549,18 +5504,13 @@ namespace {
55495504
55505505 // Unwrap the last component type, preserving @lvalue-ness.
55515506 auto optionalTy = components.back ().getComponentType ();
5507+ assert (!optionalTy->hasUnresolvedType ());
55525508 Type objectTy;
55535509 if (auto lvalue = optionalTy->getAs <LValueType>()) {
55545510 objectTy = lvalue->getObjectType ()->getOptionalObjectType ();
5555- if (optionalTy->hasUnresolvedType () && !objectTy) {
5556- objectTy = optionalTy;
5557- }
55585511 objectTy = LValueType::get (objectTy);
55595512 } else {
55605513 objectTy = optionalTy->getOptionalObjectType ();
5561- if (optionalTy->hasUnresolvedType () && !objectTy) {
5562- objectTy = optionalTy;
5563- }
55645514 }
55655515 assert (objectTy);
55665516
@@ -7160,12 +7110,10 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
71607110 Type openedFromInstanceType = openedFromType;
71617111
71627112 // Look through metatypes.
7163- while ((fromInstanceType->is <UnresolvedType>() ||
7164- fromInstanceType->is <AnyMetatypeType>()) &&
7113+ while (fromInstanceType->is <AnyMetatypeType>() &&
71657114 toInstanceType->is <ExistentialMetatypeType>()) {
7166- if (!fromInstanceType->is <UnresolvedType>())
7167- fromInstanceType = fromInstanceType->getMetatypeInstanceType ();
7168- if (openedFromInstanceType && !openedFromInstanceType->is <UnresolvedType>())
7115+ fromInstanceType = fromInstanceType->getMetatypeInstanceType ();
7116+ if (openedFromInstanceType)
71697117 openedFromInstanceType = openedFromInstanceType->getMetatypeInstanceType ();
71707118 toInstanceType = toInstanceType->getMetatypeInstanceType ();
71717119 }
@@ -7297,8 +7245,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
72977245 if (knownRestriction != solution.ConstraintRestrictions .end ()) {
72987246 switch (knownRestriction->second ) {
72997247 case ConversionRestrictionKind::DeepEquality: {
7300- if (toType->hasUnresolvedType ())
7301- break ;
7248+ assert (!toType->hasUnresolvedType ());
73027249
73037250 // HACK: Fix problem related to Swift 4 mode (with assertions),
73047251 // since Swift 4 mode allows passing arguments with extra parens
@@ -8172,9 +8119,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
81728119 }
81738120 }
81748121
8175- // Unresolved types come up in diagnostics for lvalue and inout types.
8176- if (fromType->hasUnresolvedType () || toType->hasUnresolvedType ())
8177- return cs.cacheType (new (ctx) UnresolvedTypeConversionExpr (expr, toType));
8122+ assert (!fromType->hasUnresolvedType ());
8123+ assert (!toType->hasUnresolvedType ());
81788124
81798125 ABORT ([&](auto &out) {
81808126 out << " Unhandled coercion:\n " ;
@@ -8723,11 +8669,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
87238669
87248670 // FIXME: Handle unwrapping everywhere else.
87258671
8726- // If this is an UnresolvedType in the system, preserve it.
8727- if (cs.getType (fn)->is <UnresolvedType>()) {
8728- cs.setType (apply, cs.getType (fn));
8729- return apply;
8730- }
8672+ assert (!cs.getType (fn)->is <UnresolvedType>());
87318673
87328674 // We have a type constructor.
87338675 auto metaTy = cs.getType (fn)->castTo <AnyMetatypeType>();
@@ -8754,22 +8696,16 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
87548696 auto *ctorLocator =
87558697 cs.getConstraintLocator (locator, {ConstraintLocator::ApplyFunction,
87568698 ConstraintLocator::ConstructorMember});
8757- auto selected = solution.getOverloadChoiceIfAvailable (ctorLocator);
8758- if (!selected) {
8759- assert (ty->hasError () || ty->hasUnresolvedType ());
8760- cs.setType (apply, ty);
8761- return apply;
8762- }
8699+ auto selected = solution.getOverloadChoice (ctorLocator);
87638700
87648701 assert (ty->getNominalOrBoundGenericNominal () || ty->is <DynamicSelfType>() ||
87658702 ty->isExistentialType () || ty->is <ArchetypeType>());
87668703
87678704 // Consider the constructor decl reference expr 'implicit', but the
87688705 // constructor call expr itself has the apply's 'implicitness'.
8769- Expr *declRef = buildMemberRef (fn, /* dotLoc=*/ SourceLoc (), *selected,
8770- DeclNameLoc (fn->getEndLoc ()), locator,
8771- ctorLocator, /* implicit=*/ true ,
8772- AccessSemantics::Ordinary);
8706+ Expr *declRef = buildMemberRef (
8707+ fn, /* dotLoc=*/ SourceLoc (), selected, DeclNameLoc (fn->getEndLoc ()),
8708+ locator, ctorLocator, /* implicit=*/ true , AccessSemantics::Ordinary);
87738709 if (!declRef)
87748710 return nullptr ;
87758711
0 commit comments