@@ -3298,11 +3298,7 @@ namespace {
3298
3298
auto cond
3299
3299
= solution.convertBooleanTypeToBuiltinI1 (expr->getCondExpr (),
3300
3300
cs.getConstraintLocator (expr));
3301
- if (!cond) {
3302
- cs.setType (expr->getCondExpr (), ErrorType::get (resultTy));
3303
- } else {
3304
- expr->setCondExpr (cond);
3305
- }
3301
+ expr->setCondExpr (cond);
3306
3302
3307
3303
// Coerce the then/else branches to the common type.
3308
3304
expr->setThenExpr (coerceToType (expr->getThenExpr (), resultTy,
@@ -8502,45 +8498,48 @@ Solution::convertBooleanTypeToBuiltinI1(Expr *expr,
8502
8498
// Find the builtin method.
8503
8499
if (members.size () != 1 ) {
8504
8500
tc.diagnose (expr->getLoc (), diag::broken_bool);
8505
- return nullptr ;
8501
+ return expr ;
8506
8502
}
8507
8503
auto *builtinMethod = dyn_cast<FuncDecl>(members[0 ].getValueDecl ());
8508
8504
if (!builtinMethod) {
8509
8505
tc.diagnose (expr->getLoc (), diag::broken_bool);
8510
- return nullptr ;
8506
+ return expr ;
8511
8507
}
8512
8508
8513
- // Form a reference to the builtin method.
8514
- Expr *memberRef = new (ctx) MemberRefExpr (expr, SourceLoc (),
8515
- builtinMethod,
8516
- DeclNameLoc (expr->getLoc ()),
8517
- /* Implicit=*/ true );
8518
- cs.cacheSubExprTypes (memberRef);
8519
- cs.setSubExprTypes (memberRef);
8520
- bool failed = tc.typeCheckExpressionShallow (memberRef, cs.DC );
8521
- cs.cacheExprTypes (memberRef);
8522
- assert (!failed && " Could not reference witness?" );
8523
- (void )failed;
8509
+ // The method is not generic, so there are no substitutions.
8510
+ auto builtinMethodType = builtinMethod->getInterfaceType ()
8511
+ ->castTo <FunctionType>();
8512
+
8513
+ // Form an unbound reference to the builtin method.
8514
+ auto *declRef = new (ctx) DeclRefExpr (builtinMethod,
8515
+ DeclNameLoc (expr->getLoc ()),
8516
+ /* Implicit=*/ true );
8517
+ declRef->setFunctionRefKind (FunctionRefKind::DoubleApply);
8518
+ cs.setType (declRef, builtinMethodType);
8524
8519
8525
- // Call the builtin method.
8526
8520
auto getType = [&](const Expr *E) -> Type {
8527
8521
return cs.getType (E);
8528
8522
};
8529
8523
8530
- expr = CallExpr::createImplicit (ctx, memberRef, { }, { }, getType);
8531
- cs.cacheSubExprTypes (expr);
8532
- cs.setSubExprTypes (expr);
8533
- failed = tc.typeCheckExpressionShallow (expr, cs.DC );
8534
- cs.cacheExprTypes (expr);
8535
- assert (!failed && " Could not call witness?" );
8536
- (void )failed;
8524
+ // Apply 'self' to get the method value.
8525
+ auto *methodRef = new (ctx) DotSyntaxCallExpr (declRef,
8526
+ SourceLoc (),
8527
+ expr);
8528
+ cs.setType (methodRef, builtinMethodType->getResult ());
8537
8529
8538
- if (expr && !cs.getType (expr)->isBuiltinIntegerType (1 )) {
8530
+ // Apply the empty argument list to get the final result.
8531
+ auto *result = CallExpr::createImplicit (ctx, methodRef,
8532
+ { }, { }, getType);
8533
+ cs.setType (result, builtinMethodType->getResult ()
8534
+ ->castTo <FunctionType>()->getResult ());
8535
+ cs.setType (result->getArg (), ctx.TheEmptyTupleType );
8536
+
8537
+ if (!cs.getType (result)->isBuiltinIntegerType (1 )) {
8539
8538
tc.diagnose (expr->getLoc (), diag::broken_bool);
8540
- return nullptr ;
8539
+ return result ;
8541
8540
}
8542
8541
8543
- return expr ;
8542
+ return result ;
8544
8543
}
8545
8544
8546
8545
Expr *Solution::convertOptionalToBool (Expr *expr,
0 commit comments