@@ -2679,8 +2679,7 @@ namespace {
2679
2679
auto type = simplifyType (openedType);
2680
2680
cs.setType (expr, type);
2681
2681
2682
- if (type->is <UnresolvedType>())
2683
- return expr;
2682
+ assert (!type->is <UnresolvedType>());
2684
2683
2685
2684
auto &ctx = cs.getASTContext ();
2686
2685
@@ -2703,14 +2702,11 @@ namespace {
2703
2702
ConcreteDeclRef witness = conformance.getWitnessByName (
2704
2703
conformingType->getRValueType (), constrName);
2705
2704
2706
- auto selectedOverload = solution.getOverloadChoiceIfAvailable (
2705
+ auto selectedOverload = solution.getOverloadChoice (
2707
2706
cs.getConstraintLocator (expr, ConstraintLocator::ConstructorMember));
2708
2707
2709
- if (!selectedOverload)
2710
- return nullptr ;
2711
-
2712
2708
auto fnType =
2713
- simplifyType (selectedOverload-> openedType )->castTo <FunctionType>();
2709
+ simplifyType (selectedOverload. openedType )->castTo <FunctionType>();
2714
2710
2715
2711
auto newArg = coerceCallArguments (
2716
2712
expr->getArg (), fnType, witness,
@@ -3009,18 +3005,8 @@ namespace {
3009
3005
// Determine the declaration selected for this overloaded reference.
3010
3006
auto memberLocator = cs.getConstraintLocator (expr,
3011
3007
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);
3022
3009
3023
- auto selected = *selectedElt;
3024
3010
if (!selected.choice .getBaseType ()) {
3025
3011
// This is one of the "outer alternatives", meaning the innermost
3026
3012
// methods didn't work out.
@@ -3252,40 +3238,19 @@ namespace {
3252
3238
Expr *visitSubscriptExpr (SubscriptExpr *expr) {
3253
3239
auto *memberLocator =
3254
3240
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);
3277
3242
3278
- if (overload-> choice .getKind () ==
3243
+ if (overload. choice .getKind () ==
3279
3244
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
3280
3245
return buildDynamicMemberLookupRef (
3281
3246
expr, expr->getBase (), expr->getIndex ()->getStartLoc (), SourceLoc (),
3282
- * overload, memberLocator);
3247
+ overload, memberLocator);
3283
3248
}
3284
3249
3285
3250
return buildSubscript (
3286
3251
expr->getBase (), expr->getIndex (), expr->getArgumentLabels (),
3287
3252
expr->hasTrailingClosure (), cs.getConstraintLocator (expr),
3288
- expr->isImplicit (), expr->getAccessSemantics (), * overload);
3253
+ expr->isImplicit (), expr->getAccessSemantics (), overload);
3289
3254
}
3290
3255
3291
3256
// / "Finish" an array expression by filling in the semantic expression.
@@ -4146,8 +4111,7 @@ namespace {
4146
4111
expr->getSubPattern ()->forEachVariable ([](VarDecl *VD) {
4147
4112
VD->setInvalid ();
4148
4113
});
4149
- if (!SuppressDiagnostics
4150
- && !cs.getType (simplified)->is <UnresolvedType>()) {
4114
+ if (!SuppressDiagnostics) {
4151
4115
auto &de = cs.getASTContext ().Diags ;
4152
4116
de.diagnose (simplified->getLoc (), diag::pattern_in_expr,
4153
4117
expr->getSubPattern ()->getKind ());
@@ -4626,18 +4590,12 @@ namespace {
4626
4590
// If this is an unresolved link, make sure we resolved it.
4627
4591
if (kind == KeyPathExpr::Component::Kind::UnresolvedProperty ||
4628
4592
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);
4636
4594
4637
4595
isDynamicMember =
4638
- foundDecl-> choice .getKind () ==
4596
+ foundDecl. choice .getKind () ==
4639
4597
OverloadChoiceKind::DynamicMemberLookup ||
4640
- foundDecl-> choice .getKind () ==
4598
+ foundDecl. choice .getKind () ==
4641
4599
OverloadChoiceKind::KeyPathDynamicMemberLookup;
4642
4600
4643
4601
// If this was a @dynamicMemberLookup property, then we actually
@@ -4668,11 +4626,9 @@ namespace {
4668
4626
case KeyPathExpr::Component::Kind::OptionalChain: {
4669
4627
didOptionalChain = true ;
4670
4628
// Chaining always forces the element to be an rvalue.
4629
+ assert (!componentTy->hasUnresolvedType ());
4671
4630
auto objectTy =
4672
4631
componentTy->getWithoutSpecifierType ()->getOptionalObjectType ();
4673
- if (componentTy->hasUnresolvedType () && !objectTy) {
4674
- objectTy = componentTy;
4675
- }
4676
4632
assert (objectTy);
4677
4633
4678
4634
auto loc = origComponent.getLoc ();
@@ -4724,8 +4680,8 @@ namespace {
4724
4680
}
4725
4681
4726
4682
// Wrap a non-optional result if there was chaining involved.
4683
+ assert (!componentTy->hasUnresolvedType ());
4727
4684
if (didOptionalChain && componentTy &&
4728
- !componentTy->hasUnresolvedType () &&
4729
4685
!componentTy->getWithoutSpecifierType ()->isEqual (leafTy)) {
4730
4686
assert (leafTy->getOptionalObjectType ()->isEqual (
4731
4687
componentTy->getWithoutSpecifierType ()));
@@ -4744,8 +4700,8 @@ namespace {
4744
4700
4745
4701
// The final component type ought to line up with the leaf type of the
4746
4702
// key path.
4747
- assert (!componentTy || componentTy ->hasUnresolvedType ()
4748
- || componentTy->getWithoutSpecifierType ()->isEqual (leafTy));
4703
+ assert (!componentTy->hasUnresolvedType ());
4704
+ assert ( componentTy->getWithoutSpecifierType ()->isEqual (leafTy));
4749
4705
4750
4706
if (!isFunctionType)
4751
4707
return E;
@@ -4850,18 +4806,13 @@ namespace {
4850
4806
4851
4807
// Unwrap the last component type, preserving @lvalue-ness.
4852
4808
auto optionalTy = components.back ().getComponentType ();
4809
+ assert (!optionalTy->hasUnresolvedType ());
4853
4810
Type objectTy;
4854
4811
if (auto lvalue = optionalTy->getAs <LValueType>()) {
4855
4812
objectTy = lvalue->getObjectType ()->getOptionalObjectType ();
4856
- if (optionalTy->hasUnresolvedType () && !objectTy) {
4857
- objectTy = optionalTy;
4858
- }
4859
4813
objectTy = LValueType::get (objectTy);
4860
4814
} else {
4861
4815
objectTy = optionalTy->getOptionalObjectType ();
4862
- if (optionalTy->hasUnresolvedType () && !objectTy) {
4863
- objectTy = optionalTy;
4864
- }
4865
4816
}
4866
4817
assert (objectTy);
4867
4818
@@ -5290,11 +5241,9 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType) {
5290
5241
Type toInstanceType = toType;
5291
5242
5292
5243
// Look through metatypes
5293
- while ((fromInstanceType->is <UnresolvedType>() ||
5294
- fromInstanceType->is <AnyMetatypeType>()) &&
5244
+ while (fromInstanceType->is <AnyMetatypeType>() &&
5295
5245
toInstanceType->is <ExistentialMetatypeType>()) {
5296
- if (!fromInstanceType->is <UnresolvedType>())
5297
- fromInstanceType = fromInstanceType->castTo <AnyMetatypeType>()->getInstanceType ();
5246
+ fromInstanceType = fromInstanceType->castTo <AnyMetatypeType>()->getInstanceType ();
5298
5247
toInstanceType = toInstanceType->castTo <ExistentialMetatypeType>()->getInstanceType ();
5299
5248
}
5300
5249
@@ -5492,11 +5441,6 @@ Expr *ExprRewriter::coerceCallArguments(
5492
5441
LocatorPathElt::ApplyArgToParam (argIdx, paramIdx, flags));
5493
5442
};
5494
5443
5495
- bool matchCanFail =
5496
- llvm::any_of (params, [](const AnyFunctionType::Param ¶m) {
5497
- return param.getPlainType ()->hasUnresolvedType ();
5498
- });
5499
-
5500
5444
// Determine whether this application has curried self.
5501
5445
bool skipCurriedSelf = apply ? hasCurriedSelf (cs, callee, apply) : true ;
5502
5446
// Determine the parameter bindings.
@@ -5554,9 +5498,7 @@ Expr *ExprRewriter::coerceCallArguments(
5554
5498
args, params, paramInfo, unlabeledTrailingClosureIndex,
5555
5499
/* allowFixes=*/ false , listener, trailingClosureMatching);
5556
5500
5557
- assert ((matchCanFail || callArgumentMatch) &&
5558
- " Call arguments did not match up?" );
5559
- (void )matchCanFail;
5501
+ assert (callArgumentMatch && " Call arguments did not match up?" );
5560
5502
5561
5503
auto parameterBindings = std::move (callArgumentMatch->parameterBindings );
5562
5504
@@ -6279,8 +6221,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
6279
6221
if (knownRestriction != solution.ConstraintRestrictions .end ()) {
6280
6222
switch (knownRestriction->second ) {
6281
6223
case ConversionRestrictionKind::DeepEquality: {
6282
- if (toType->hasUnresolvedType ())
6283
- break ;
6224
+ assert (!toType->hasUnresolvedType ());
6284
6225
6285
6226
// HACK: Fix problem related to Swift 4 mode (with assertions),
6286
6227
// since Swift 4 mode allows passing arguments with extra parens
@@ -6826,9 +6767,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
6826
6767
break ;
6827
6768
}
6828
6769
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 ());
6832
6772
6833
6773
// Use an opaque type to abstract a value of the underlying concrete type.
6834
6774
if (toType->getAs <OpaqueTypeArchetypeType>()) {
@@ -7401,19 +7341,14 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
7401
7341
// FIXME: handle unwrapping everywhere else
7402
7342
assert (!unwrapResult);
7403
7343
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>());
7409
7345
7410
7346
// We have a type constructor.
7411
7347
auto metaTy = cs.getType (fn)->castTo <AnyMetatypeType>();
7412
7348
auto ty = metaTy->getInstanceType ();
7413
7349
7414
7350
// If we're "constructing" a tuple type, it's simply a conversion.
7415
7351
if (auto tupleTy = ty->getAs <TupleType>()) {
7416
- // FIXME: Need an AST to represent this properly.
7417
7352
return coerceToType (apply->getArg (), tupleTy, locator);
7418
7353
}
7419
7354
@@ -7422,19 +7357,14 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
7422
7357
auto *ctorLocator =
7423
7358
cs.getConstraintLocator (locator, {ConstraintLocator::ApplyFunction,
7424
7359
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);
7431
7361
7432
7362
assert (ty->getNominalOrBoundGenericNominal () || ty->is <DynamicSelfType>() ||
7433
7363
ty->isExistentialType () || ty->is <ArchetypeType>());
7434
7364
7435
7365
// Consider the constructor decl reference expr 'implicit', but the
7436
7366
// 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,
7438
7368
DeclNameLoc (fn->getEndLoc ()), locator,
7439
7369
ctorLocator, /* implicit=*/ true ,
7440
7370
AccessSemantics::Ordinary);
0 commit comments