@@ -2679,8 +2679,7 @@ namespace {
26792679 auto type = simplifyType (openedType);
26802680 cs.setType (expr, type);
26812681
2682- if (type->is <UnresolvedType>())
2683- return expr;
2682+ assert (!type->is <UnresolvedType>());
26842683
26852684 auto &ctx = cs.getASTContext ();
26862685
@@ -2703,14 +2702,11 @@ namespace {
27032702 ConcreteDeclRef witness = conformance.getWitnessByName (
27042703 conformingType->getRValueType (), constrName);
27052704
2706- auto selectedOverload = solution.getOverloadChoiceIfAvailable (
2705+ auto selectedOverload = solution.getOverloadChoice (
27072706 cs.getConstraintLocator (expr, ConstraintLocator::ConstructorMember));
27082707
2709- if (!selectedOverload)
2710- return nullptr ;
2711-
27122708 auto fnType =
2713- simplifyType (selectedOverload-> openedType )->castTo <FunctionType>();
2709+ simplifyType (selectedOverload. openedType )->castTo <FunctionType>();
27142710
27152711 auto newArg = coerceCallArguments (
27162712 expr->getArg (), fnType, witness,
@@ -3009,18 +3005,8 @@ namespace {
30093005 // Determine the declaration selected for this overloaded reference.
30103006 auto memberLocator = cs.getConstraintLocator (expr,
30113007 ConstraintLocator::Member);
3012- auto selectedElt = solution.getOverloadChoiceIfAvailable (memberLocator);
3013-
3014- if (!selectedElt) {
3015- // If constraint solving resolved this to an UnresolvedType, then we're
3016- // in an ambiguity tolerant mode used for diagnostic generation. Just
3017- // leave this as whatever type of member reference it already is.
3018- Type resultTy = simplifyType (cs.getType (expr));
3019- cs.setType (expr, resultTy);
3020- return expr;
3021- }
3008+ auto selected = solution.getOverloadChoice (memberLocator);
30223009
3023- auto selected = *selectedElt;
30243010 if (!selected.choice .getBaseType ()) {
30253011 // This is one of the "outer alternatives", meaning the innermost
30263012 // methods didn't work out.
@@ -3252,40 +3238,19 @@ namespace {
32523238 Expr *visitSubscriptExpr (SubscriptExpr *expr) {
32533239 auto *memberLocator =
32543240 cs.getConstraintLocator (expr, ConstraintLocator::SubscriptMember);
3255- auto overload = solution.getOverloadChoiceIfAvailable (memberLocator);
3256-
3257- // Handles situation where there was a solution available but it didn't
3258- // have a proper overload selected from subscript call, might be because
3259- // solver was allowed to return free or unresolved types, which can
3260- // happen while running diagnostics on one of the expressions.
3261- if (!overload) {
3262- auto *base = expr->getBase ();
3263- auto &de = cs.getASTContext ().Diags ;
3264- auto baseType = cs.getType (base);
3265-
3266- if (auto errorType = baseType->getAs <ErrorType>()) {
3267- de.diagnose (base->getLoc (), diag::cannot_subscript_base,
3268- errorType->getOriginalType ())
3269- .highlight (base->getSourceRange ());
3270- } else {
3271- de.diagnose (base->getLoc (), diag::cannot_subscript_ambiguous_base)
3272- .highlight (base->getSourceRange ());
3273- }
3274-
3275- return nullptr ;
3276- }
3241+ auto overload = solution.getOverloadChoice (memberLocator);
32773242
3278- if (overload-> choice .getKind () ==
3243+ if (overload. choice .getKind () ==
32793244 OverloadChoiceKind::KeyPathDynamicMemberLookup) {
32803245 return buildDynamicMemberLookupRef (
32813246 expr, expr->getBase (), expr->getIndex ()->getStartLoc (), SourceLoc (),
3282- * overload, memberLocator);
3247+ overload, memberLocator);
32833248 }
32843249
32853250 return buildSubscript (
32863251 expr->getBase (), expr->getIndex (), expr->getArgumentLabels (),
32873252 expr->hasTrailingClosure (), cs.getConstraintLocator (expr),
3288- expr->isImplicit (), expr->getAccessSemantics (), * overload);
3253+ expr->isImplicit (), expr->getAccessSemantics (), overload);
32893254 }
32903255
32913256 // / "Finish" an array expression by filling in the semantic expression.
@@ -4146,8 +4111,7 @@ namespace {
41464111 expr->getSubPattern ()->forEachVariable ([](VarDecl *VD) {
41474112 VD->setInvalid ();
41484113 });
4149- if (!SuppressDiagnostics
4150- && !cs.getType (simplified)->is <UnresolvedType>()) {
4114+ if (!SuppressDiagnostics) {
41514115 auto &de = cs.getASTContext ().Diags ;
41524116 de.diagnose (simplified->getLoc (), diag::pattern_in_expr,
41534117 expr->getSubPattern ()->getKind ());
@@ -4626,18 +4590,12 @@ namespace {
46264590 // If this is an unresolved link, make sure we resolved it.
46274591 if (kind == KeyPathExpr::Component::Kind::UnresolvedProperty ||
46284592 kind == KeyPathExpr::Component::Kind::UnresolvedSubscript) {
4629- auto foundDecl = solution.getOverloadChoiceIfAvailable (locator);
4630- if (!foundDecl) {
4631- // If we couldn't resolve the component, leave it alone.
4632- resolvedComponents.push_back (origComponent);
4633- componentTy = origComponent.getComponentType ();
4634- continue ;
4635- }
4593+ auto foundDecl = solution.getOverloadChoice (locator);
46364594
46374595 isDynamicMember =
4638- foundDecl-> choice .getKind () ==
4596+ foundDecl. choice .getKind () ==
46394597 OverloadChoiceKind::DynamicMemberLookup ||
4640- foundDecl-> choice .getKind () ==
4598+ foundDecl. choice .getKind () ==
46414599 OverloadChoiceKind::KeyPathDynamicMemberLookup;
46424600
46434601 // If this was a @dynamicMemberLookup property, then we actually
@@ -4668,11 +4626,9 @@ namespace {
46684626 case KeyPathExpr::Component::Kind::OptionalChain: {
46694627 didOptionalChain = true ;
46704628 // Chaining always forces the element to be an rvalue.
4629+ assert (!componentTy->hasUnresolvedType ());
46714630 auto objectTy =
46724631 componentTy->getWithoutSpecifierType ()->getOptionalObjectType ();
4673- if (componentTy->hasUnresolvedType () && !objectTy) {
4674- objectTy = componentTy;
4675- }
46764632 assert (objectTy);
46774633
46784634 auto loc = origComponent.getLoc ();
@@ -4724,8 +4680,8 @@ namespace {
47244680 }
47254681
47264682 // Wrap a non-optional result if there was chaining involved.
4683+ assert (!componentTy->hasUnresolvedType ());
47274684 if (didOptionalChain && componentTy &&
4728- !componentTy->hasUnresolvedType () &&
47294685 !componentTy->getWithoutSpecifierType ()->isEqual (leafTy)) {
47304686 assert (leafTy->getOptionalObjectType ()->isEqual (
47314687 componentTy->getWithoutSpecifierType ()));
@@ -4744,8 +4700,8 @@ namespace {
47444700
47454701 // The final component type ought to line up with the leaf type of the
47464702 // key path.
4747- assert (!componentTy || componentTy ->hasUnresolvedType ()
4748- || componentTy->getWithoutSpecifierType ()->isEqual (leafTy));
4703+ assert (!componentTy->hasUnresolvedType ());
4704+ assert ( componentTy->getWithoutSpecifierType ()->isEqual (leafTy));
47494705
47504706 if (!isFunctionType)
47514707 return E;
@@ -4850,18 +4806,13 @@ namespace {
48504806
48514807 // Unwrap the last component type, preserving @lvalue-ness.
48524808 auto optionalTy = components.back ().getComponentType ();
4809+ assert (!optionalTy->hasUnresolvedType ());
48534810 Type objectTy;
48544811 if (auto lvalue = optionalTy->getAs <LValueType>()) {
48554812 objectTy = lvalue->getObjectType ()->getOptionalObjectType ();
4856- if (optionalTy->hasUnresolvedType () && !objectTy) {
4857- objectTy = optionalTy;
4858- }
48594813 objectTy = LValueType::get (objectTy);
48604814 } else {
48614815 objectTy = optionalTy->getOptionalObjectType ();
4862- if (optionalTy->hasUnresolvedType () && !objectTy) {
4863- objectTy = optionalTy;
4864- }
48654816 }
48664817 assert (objectTy);
48674818
@@ -5290,11 +5241,9 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType) {
52905241 Type toInstanceType = toType;
52915242
52925243 // Look through metatypes
5293- while ((fromInstanceType->is <UnresolvedType>() ||
5294- fromInstanceType->is <AnyMetatypeType>()) &&
5244+ while (fromInstanceType->is <AnyMetatypeType>() &&
52955245 toInstanceType->is <ExistentialMetatypeType>()) {
5296- if (!fromInstanceType->is <UnresolvedType>())
5297- fromInstanceType = fromInstanceType->castTo <AnyMetatypeType>()->getInstanceType ();
5246+ fromInstanceType = fromInstanceType->castTo <AnyMetatypeType>()->getInstanceType ();
52985247 toInstanceType = toInstanceType->castTo <ExistentialMetatypeType>()->getInstanceType ();
52995248 }
53005249
@@ -5492,11 +5441,6 @@ Expr *ExprRewriter::coerceCallArguments(
54925441 LocatorPathElt::ApplyArgToParam (argIdx, paramIdx, flags));
54935442 };
54945443
5495- bool matchCanFail =
5496- llvm::any_of (params, [](const AnyFunctionType::Param ¶m) {
5497- return param.getPlainType ()->hasUnresolvedType ();
5498- });
5499-
55005444 // Determine whether this application has curried self.
55015445 bool skipCurriedSelf = apply ? hasCurriedSelf (cs, callee, apply) : true ;
55025446 // Determine the parameter bindings.
@@ -5554,9 +5498,7 @@ Expr *ExprRewriter::coerceCallArguments(
55545498 args, params, paramInfo, unlabeledTrailingClosureIndex,
55555499 /* allowFixes=*/ false , listener, trailingClosureMatching);
55565500
5557- assert ((matchCanFail || callArgumentMatch) &&
5558- " Call arguments did not match up?" );
5559- (void )matchCanFail;
5501+ assert (callArgumentMatch && " Call arguments did not match up?" );
55605502
55615503 auto parameterBindings = std::move (callArgumentMatch->parameterBindings );
55625504
@@ -6279,8 +6221,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
62796221 if (knownRestriction != solution.ConstraintRestrictions .end ()) {
62806222 switch (knownRestriction->second ) {
62816223 case ConversionRestrictionKind::DeepEquality: {
6282- if (toType->hasUnresolvedType ())
6283- break ;
6224+ assert (!toType->hasUnresolvedType ());
62846225
62856226 // HACK: Fix problem related to Swift 4 mode (with assertions),
62866227 // since Swift 4 mode allows passing arguments with extra parens
@@ -6826,9 +6767,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
68266767 break ;
68276768 }
68286769
6829- // Unresolved types come up in diagnostics for lvalue and inout types.
6830- if (fromType->hasUnresolvedType () || toType->hasUnresolvedType ())
6831- return cs.cacheType (new (ctx) UnresolvedTypeConversionExpr (expr, toType));
6770+ assert (!fromType->hasUnresolvedType ());
6771+ assert (!toType->hasUnresolvedType ());
68326772
68336773 // Use an opaque type to abstract a value of the underlying concrete type.
68346774 if (toType->getAs <OpaqueTypeArchetypeType>()) {
@@ -7401,19 +7341,14 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
74017341 // FIXME: handle unwrapping everywhere else
74027342 assert (!unwrapResult);
74037343
7404- // If this is an UnresolvedType in the system, preserve it.
7405- if (cs.getType (fn)->is <UnresolvedType>()) {
7406- cs.setType (apply, cs.getType (fn));
7407- return apply;
7408- }
7344+ assert (!cs.getType (fn)->is <UnresolvedType>());
74097345
74107346 // We have a type constructor.
74117347 auto metaTy = cs.getType (fn)->castTo <AnyMetatypeType>();
74127348 auto ty = metaTy->getInstanceType ();
74137349
74147350 // If we're "constructing" a tuple type, it's simply a conversion.
74157351 if (auto tupleTy = ty->getAs <TupleType>()) {
7416- // FIXME: Need an AST to represent this properly.
74177352 return coerceToType (apply->getArg (), tupleTy, locator);
74187353 }
74197354
@@ -7422,19 +7357,14 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
74227357 auto *ctorLocator =
74237358 cs.getConstraintLocator (locator, {ConstraintLocator::ApplyFunction,
74247359 ConstraintLocator::ConstructorMember});
7425- auto selected = solution.getOverloadChoiceIfAvailable (ctorLocator);
7426- if (!selected) {
7427- assert (ty->hasError () || ty->hasUnresolvedType ());
7428- cs.setType (apply, ty);
7429- return apply;
7430- }
7360+ auto selected = solution.getOverloadChoice (ctorLocator);
74317361
74327362 assert (ty->getNominalOrBoundGenericNominal () || ty->is <DynamicSelfType>() ||
74337363 ty->isExistentialType () || ty->is <ArchetypeType>());
74347364
74357365 // Consider the constructor decl reference expr 'implicit', but the
74367366 // constructor call expr itself has the apply's 'implicitness'.
7437- Expr *declRef = buildMemberRef (fn, /* dotLoc=*/ SourceLoc (), * selected,
7367+ Expr *declRef = buildMemberRef (fn, /* dotLoc=*/ SourceLoc (), selected,
74387368 DeclNameLoc (fn->getEndLoc ()), locator,
74397369 ctorLocator, /* implicit=*/ true ,
74407370 AccessSemantics::Ordinary);
0 commit comments