@@ -3268,8 +3268,7 @@ namespace {
3268
3268
auto type = simplifyType (openedType);
3269
3269
cs.setType (expr, type);
3270
3270
3271
- if (type->is <UnresolvedType>())
3272
- return expr;
3271
+ assert (!type->is <UnresolvedType>());
3273
3272
3274
3273
Type conformingType = type;
3275
3274
if (auto baseType = conformingType->getOptionalObjectType ()) {
@@ -3288,14 +3287,11 @@ namespace {
3288
3287
3289
3288
ConcreteDeclRef witness = conformance.getWitnessByName (constrName);
3290
3289
3291
- auto selectedOverload = solution.getOverloadChoiceIfAvailable (
3290
+ auto selectedOverload = solution.getOverloadChoice (
3292
3291
cs.getConstraintLocator (expr, ConstraintLocator::ConstructorMember));
3293
3292
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>();
3299
3295
3300
3296
auto newArgs = coerceCallArguments (
3301
3297
expr->getArgs (), fnType, witness, /* applyExpr=*/ nullptr ,
@@ -3628,18 +3624,8 @@ namespace {
3628
3624
// Determine the declaration selected for this overloaded reference.
3629
3625
auto memberLocator = cs.getConstraintLocator (expr,
3630
3626
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);
3641
3628
3642
- auto selected = *selectedElt;
3643
3629
if (!selected.choice .getBaseType ()) {
3644
3630
// This is one of the "outer alternatives", meaning the innermost
3645
3631
// methods didn't work out.
@@ -3958,39 +3944,17 @@ namespace {
3958
3944
Expr *visitSubscriptExpr (SubscriptExpr *expr) {
3959
3945
auto *memberLocator =
3960
3946
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 ()) {
3985
3949
return buildDynamicMemberLookupRef (
3986
3950
expr, expr->getBase (), expr->getArgs ()->getStartLoc (), SourceLoc (),
3987
- * overload, memberLocator);
3951
+ overload, memberLocator);
3988
3952
}
3989
3953
3990
3954
return buildSubscript (expr->getBase (), expr->getArgs (),
3991
3955
cs.getConstraintLocator (expr), memberLocator,
3992
3956
expr->isImplicit (), expr->getAccessSemantics (),
3993
- * overload);
3957
+ overload);
3994
3958
}
3995
3959
3996
3960
// / "Finish" an array expression by filling in the semantic expression.
@@ -5321,15 +5285,8 @@ namespace {
5321
5285
// If this is an unresolved link, make sure we resolved it.
5322
5286
if (kind == KeyPathExpr::Component::Kind::UnresolvedMember ||
5323
5287
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 ();
5333
5290
5334
5291
// If this was a @dynamicMemberLookup property, then we actually
5335
5292
// form a subscript reference, so switch the kind.
@@ -5368,11 +5325,9 @@ namespace {
5368
5325
case KeyPathExpr::Component::Kind::OptionalChain: {
5369
5326
didOptionalChain = true ;
5370
5327
// Chaining always forces the element to be an rvalue.
5328
+ assert (!componentTy->hasUnresolvedType ());
5371
5329
auto objectTy =
5372
5330
componentTy->getWithoutSpecifierType ()->getOptionalObjectType ();
5373
- if (componentTy->hasUnresolvedType () && !objectTy) {
5374
- objectTy = componentTy;
5375
- }
5376
5331
assert (objectTy);
5377
5332
5378
5333
auto loc = origComponent.getLoc ();
@@ -5422,8 +5377,8 @@ namespace {
5422
5377
}
5423
5378
5424
5379
// Wrap a non-optional result if there was chaining involved.
5380
+ assert (!componentTy->hasUnresolvedType ());
5425
5381
if (didOptionalChain && componentTy &&
5426
- !componentTy->hasUnresolvedType () &&
5427
5382
!componentTy->getWithoutSpecifierType ()->isEqual (leafTy)) {
5428
5383
auto component = KeyPathExpr::Component::forOptionalWrap (leafTy);
5429
5384
resolvedComponents.push_back (component);
@@ -5549,18 +5504,13 @@ namespace {
5549
5504
5550
5505
// Unwrap the last component type, preserving @lvalue-ness.
5551
5506
auto optionalTy = components.back ().getComponentType ();
5507
+ assert (!optionalTy->hasUnresolvedType ());
5552
5508
Type objectTy;
5553
5509
if (auto lvalue = optionalTy->getAs <LValueType>()) {
5554
5510
objectTy = lvalue->getObjectType ()->getOptionalObjectType ();
5555
- if (optionalTy->hasUnresolvedType () && !objectTy) {
5556
- objectTy = optionalTy;
5557
- }
5558
5511
objectTy = LValueType::get (objectTy);
5559
5512
} else {
5560
5513
objectTy = optionalTy->getOptionalObjectType ();
5561
- if (optionalTy->hasUnresolvedType () && !objectTy) {
5562
- objectTy = optionalTy;
5563
- }
5564
5514
}
5565
5515
assert (objectTy);
5566
5516
@@ -7160,12 +7110,10 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
7160
7110
Type openedFromInstanceType = openedFromType;
7161
7111
7162
7112
// Look through metatypes.
7163
- while ((fromInstanceType->is <UnresolvedType>() ||
7164
- fromInstanceType->is <AnyMetatypeType>()) &&
7113
+ while (fromInstanceType->is <AnyMetatypeType>() &&
7165
7114
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)
7169
7117
openedFromInstanceType = openedFromInstanceType->getMetatypeInstanceType ();
7170
7118
toInstanceType = toInstanceType->getMetatypeInstanceType ();
7171
7119
}
@@ -7297,8 +7245,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
7297
7245
if (knownRestriction != solution.ConstraintRestrictions .end ()) {
7298
7246
switch (knownRestriction->second ) {
7299
7247
case ConversionRestrictionKind::DeepEquality: {
7300
- if (toType->hasUnresolvedType ())
7301
- break ;
7248
+ assert (!toType->hasUnresolvedType ());
7302
7249
7303
7250
// HACK: Fix problem related to Swift 4 mode (with assertions),
7304
7251
// since Swift 4 mode allows passing arguments with extra parens
@@ -8172,9 +8119,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
8172
8119
}
8173
8120
}
8174
8121
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 ());
8178
8124
8179
8125
ABORT ([&](auto &out) {
8180
8126
out << " Unhandled coercion:\n " ;
@@ -8723,11 +8669,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
8723
8669
8724
8670
// FIXME: Handle unwrapping everywhere else.
8725
8671
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>());
8731
8673
8732
8674
// We have a type constructor.
8733
8675
auto metaTy = cs.getType (fn)->castTo <AnyMetatypeType>();
@@ -8754,22 +8696,16 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
8754
8696
auto *ctorLocator =
8755
8697
cs.getConstraintLocator (locator, {ConstraintLocator::ApplyFunction,
8756
8698
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);
8763
8700
8764
8701
assert (ty->getNominalOrBoundGenericNominal () || ty->is <DynamicSelfType>() ||
8765
8702
ty->isExistentialType () || ty->is <ArchetypeType>());
8766
8703
8767
8704
// Consider the constructor decl reference expr 'implicit', but the
8768
8705
// 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);
8773
8709
if (!declRef)
8774
8710
return nullptr ;
8775
8711
0 commit comments