@@ -2690,7 +2690,7 @@ namespace {
2690
2690
CS.addConstraint (ConstraintKind::Defaultable,
2691
2691
placeholderTy, TupleType::getEmpty (CS.getASTContext ()),
2692
2692
locator);
2693
- E-> setType (placeholderTy);
2693
+ CS. setType (E, placeholderTy);
2694
2694
}
2695
2695
// NOTE: The type loc may be there but have failed to validate, in which
2696
2696
// case we return the null type.
@@ -2803,10 +2803,11 @@ namespace {
2803
2803
// For closures containing only a single expression, the body participates
2804
2804
// in type checking.
2805
2805
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
2806
+ auto &CS = CG.getConstraintSystem ();
2806
2807
if (closure->hasSingleExpressionBody ()) {
2807
2808
// Visit the closure itself, which produces a function type.
2808
2809
auto funcTy = CG.visit (expr)->castTo <FunctionType>();
2809
- expr-> setType (funcTy);
2810
+ CS. setType (expr, funcTy);
2810
2811
}
2811
2812
2812
2813
return { true , expr };
@@ -2828,18 +2829,23 @@ namespace {
2828
2829
// / generate constraints from the expression.
2829
2830
Expr *walkToExprPost (Expr *expr) override {
2830
2831
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
2831
- // If the function type has an error in it, we don't want to solve the
2832
- // system.
2833
- if (closure->getType () &&
2834
- (closure->getType ()->hasError () ||
2835
- closure->getType ()->getCanonicalType ()->hasError ()))
2836
- return nullptr ;
2837
-
2838
2832
if (closure->hasSingleExpressionBody ()) {
2833
+ auto &CS = CG.getConstraintSystem ();
2834
+ Type closureTy = closure->getType ();
2835
+
2836
+ // If the function type has an error in it, we don't want to solve the
2837
+ // system.
2838
+ if (closureTy &&
2839
+ (closureTy->hasError () ||
2840
+ closureTy->getCanonicalType ()->hasError ()))
2841
+ return nullptr ;
2842
+
2843
+ CS.setType (closure, closureTy);
2844
+
2839
2845
// Visit the body. It's type needs to be convertible to the function's
2840
2846
// return type.
2841
- auto resultTy = closure-> getResultType ();
2842
- auto bodyTy = closure->getSingleExpressionBody ()->getType ();
2847
+ auto resultTy = closureTy-> castTo <FunctionType>()-> getResult ();
2848
+ Type bodyTy = closure->getSingleExpressionBody ()->getType ();
2843
2849
CG.getConstraintSystem ().setFavoredType (expr, bodyTy.getPointer ());
2844
2850
CG.getConstraintSystem ()
2845
2851
.addConstraint (ConstraintKind::Conversion, bodyTy,
@@ -2853,7 +2859,11 @@ namespace {
2853
2859
}
2854
2860
2855
2861
if (auto type = CG.visit (expr)) {
2856
- expr->setType (CG.getConstraintSystem ().simplifyType (type));
2862
+ auto &CS = CG.getConstraintSystem ();
2863
+ auto simplifiedType = CS.simplifyType (type);
2864
+
2865
+ CS.setType (expr, simplifiedType);
2866
+
2857
2867
return expr;
2858
2868
}
2859
2869
@@ -2954,7 +2964,9 @@ Expr *ConstraintSystem::generateConstraintsShallow(Expr *expr) {
2954
2964
2955
2965
this ->optimizeConstraints (expr);
2956
2966
2957
- expr->setType (type);
2967
+ auto &CS = CG.getConstraintSystem ();
2968
+ CS.setType (expr, type);
2969
+
2958
2970
return expr;
2959
2971
}
2960
2972
0 commit comments