@@ -1894,38 +1894,6 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
1894
1894
typeExpr->getTypeLoc ());
1895
1895
}
1896
1896
1897
- // / \brief Clean up the given ill-formed expression, removing any references
1898
- // / to type variables and setting error types on erroneous expression nodes.
1899
- void CleanupIllFormedExpressionRAII::doIt (Expr *expr) {
1900
- class CleanupIllFormedExpression : public ASTWalker {
1901
- public:
1902
- bool walkToDeclPre (Decl *D) override {
1903
- // This handles parameter decls in ClosureExprs.
1904
- if (auto VD = dyn_cast<VarDecl>(D)) {
1905
- if (VD->hasType () && VD->getType ()->hasTypeVariable ()) {
1906
- VD->markInvalid ();
1907
- }
1908
- }
1909
- return true ;
1910
- }
1911
-
1912
- // Don't walk into statements. This handles the BraceStmt in
1913
- // non-single-expr closures, so we don't walk into their body.
1914
- std::pair<bool , Stmt *> walkToStmtPre (Stmt *S) override {
1915
- return { false , S };
1916
- }
1917
- };
1918
-
1919
- if (expr)
1920
- expr->walk (CleanupIllFormedExpression ());
1921
- }
1922
-
1923
-
1924
- CleanupIllFormedExpressionRAII::~CleanupIllFormedExpressionRAII () {
1925
- if (expr)
1926
- CleanupIllFormedExpressionRAII::doIt (*expr);
1927
- }
1928
-
1929
1897
// / Pre-check the expression, validating any types that occur in the
1930
1898
// / expression and folding sequence expressions.
1931
1899
bool TypeChecker::preCheckExpression (Expr *&expr, DeclContext *dc) {
@@ -2004,7 +1972,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2004
1972
2005
1973
ConstraintSystem cs (*this , dc, csOptions);
2006
1974
cs.baseCS = baseCS;
2007
- CleanupIllFormedExpressionRAII cleanup (expr);
2008
1975
2009
1976
// Verify that a purpose was specified if a convertType was. Note that it is
2010
1977
// ok to have a purpose without a convertType (which is used for call
@@ -2071,10 +2038,8 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2071
2038
return Type ();
2072
2039
}
2073
2040
2074
- if (options.contains (TypeCheckExprFlags::SkipApplyingSolution)) {
2075
- cleanup.disable ();
2041
+ if (options.contains (TypeCheckExprFlags::SkipApplyingSolution))
2076
2042
return solution.simplifyType (cs.getType (expr));
2077
- }
2078
2043
2079
2044
// Apply the solution to the expression.
2080
2045
result = cs.applySolution (
@@ -2109,7 +2074,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
2109
2074
}
2110
2075
2111
2076
expr = result;
2112
- cleanup.disable ();
2113
2077
return cs.getType (expr);
2114
2078
}
2115
2079
@@ -2123,7 +2087,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
2123
2087
2124
2088
// Construct a constraint system from this expression.
2125
2089
ConstraintSystem cs (*this , dc, ConstraintSystemFlags::SuppressDiagnostics);
2126
- CleanupIllFormedExpressionRAII cleanup (expr);
2127
2090
2128
2091
// Attempt to solve the constraint system.
2129
2092
SmallVector<Solution, 4 > viable;
@@ -2212,18 +2175,12 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
2212
2175
// Attempt to solve the constraint system.
2213
2176
SmallVector<Solution, 4 > viable;
2214
2177
2215
- // If the previous checking gives the expr error type,
2216
- // clear the result and re-check.
2217
- {
2218
- CleanupIllFormedExpressionRAII cleanup (expr);
2178
+ const Type originalType = expr->getType ();
2179
+ if (originalType && originalType->hasError ())
2180
+ expr->setType (Type ());
2219
2181
2220
- const Type originalType = expr->getType ();
2221
- if (originalType && originalType->hasError ())
2222
- expr->setType (Type ());
2223
-
2224
- cs.solve (expr, /* convertType*/ Type (), listener, viable,
2225
- allowFreeTypeVariables);
2226
- }
2182
+ cs.solve (expr, /* convertType*/ Type (), listener, viable,
2183
+ allowFreeTypeVariables);
2227
2184
2228
2185
for (auto &solution : viable) {
2229
2186
auto exprType = solution.simplifyType (cs.getType (expr));
@@ -2237,7 +2194,6 @@ bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) {
2237
2194
2238
2195
// Construct a constraint system from this expression.
2239
2196
ConstraintSystem CS (*this , DC, ConstraintSystemFlags::SuppressDiagnostics);
2240
- CleanupIllFormedExpressionRAII cleanup (expr);
2241
2197
2242
2198
auto *SE = cast<SequenceExpr>(expr);
2243
2199
assert (SE->getNumElements () >= 3 );
@@ -2323,7 +2279,6 @@ bool TypeChecker::typeCheckExpressionShallow(Expr *&expr, DeclContext *dc) {
2323
2279
2324
2280
// Construct a constraint system from this expression.
2325
2281
ConstraintSystem cs (*this , dc, ConstraintSystemFlags::AllowFixes);
2326
- CleanupIllFormedExpressionRAII cleanup (expr);
2327
2282
if (auto generatedExpr = cs.generateConstraintsShallow (expr))
2328
2283
expr = generatedExpr;
2329
2284
else
@@ -2366,7 +2321,6 @@ bool TypeChecker::typeCheckExpressionShallow(Expr *&expr, DeclContext *dc) {
2366
2321
}
2367
2322
2368
2323
expr = result;
2369
- cleanup.disable ();
2370
2324
return false ;
2371
2325
}
2372
2326
@@ -3236,8 +3190,6 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
3236
3190
// TODO: need to add kind arg?
3237
3191
// Construct a constraint system from this expression.
3238
3192
ConstraintSystem cs (*this , dc, ConstraintSystemFlags::AllowFixes);
3239
- CleanupIllFormedExpressionRAII cleanup (expr);
3240
-
3241
3193
// If there is a type that we're expected to convert to, add the conversion
3242
3194
// constraint.
3243
3195
cs.addConstraint (ConstraintKind::Conversion, expr->getType (), type,
@@ -3285,7 +3237,6 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
3285
3237
}
3286
3238
3287
3239
expr = result;
3288
- cleanup.disable ();
3289
3240
return false ;
3290
3241
}
3291
3242
0 commit comments