@@ -1649,31 +1649,9 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
1649
1649
1650
1650
// / \brief Clean up the given ill-formed expression, removing any references
1651
1651
// / to type variables and setting error types on erroneous expression nodes.
1652
- void CleanupIllFormedExpressionRAII::doIt (Expr *expr, ASTContext &Context ) {
1652
+ void CleanupIllFormedExpressionRAII::doIt (Expr *expr) {
1653
1653
class CleanupIllFormedExpression : public ASTWalker {
1654
- ASTContext &context;
1655
-
1656
1654
public:
1657
- CleanupIllFormedExpression (ASTContext &context) : context(context) { }
1658
-
1659
- std::pair<bool , Expr *> walkToExprPre (Expr *expr) override {
1660
- // If the type of this expression has a type variable or is invalid,
1661
- // overwrite it with ErrorType.
1662
- Type type = expr->getType ();
1663
- if (type && type->hasTypeVariable ())
1664
- expr->setType (ErrorType::get (context));
1665
-
1666
- return { true , expr };
1667
- }
1668
-
1669
- // If we find a TypeLoc (e.g. in an as? expr) with a type variable, rewrite
1670
- // it.
1671
- bool walkToTypeLocPre (TypeLoc &TL) override {
1672
- if (TL.getType () && TL.getType ()->hasTypeVariable ())
1673
- TL.setType (Type (), /* was validated*/ false );
1674
- return true ;
1675
- }
1676
-
1677
1655
bool walkToDeclPre (Decl *D) override {
1678
1656
// This handles parameter decls in ClosureExprs.
1679
1657
if (auto VD = dyn_cast<VarDecl>(D)) {
@@ -1692,13 +1670,13 @@ void CleanupIllFormedExpressionRAII::doIt(Expr *expr, ASTContext &Context) {
1692
1670
};
1693
1671
1694
1672
if (expr)
1695
- expr->walk (CleanupIllFormedExpression (Context ));
1673
+ expr->walk (CleanupIllFormedExpression ());
1696
1674
}
1697
1675
1698
1676
1699
1677
CleanupIllFormedExpressionRAII::~CleanupIllFormedExpressionRAII () {
1700
1678
if (expr)
1701
- CleanupIllFormedExpressionRAII::doIt (*expr, Context );
1679
+ CleanupIllFormedExpressionRAII::doIt (*expr);
1702
1680
}
1703
1681
1704
1682
// / Pre-check the expression, validating any types that occur in the
@@ -1825,7 +1803,7 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
1825
1803
csOptions |= ConstraintSystemFlags::PreferForceUnwrapToOptional;
1826
1804
ConstraintSystem cs (*this , dc, csOptions);
1827
1805
cs.baseCS = baseCS;
1828
- CleanupIllFormedExpressionRAII cleanup (Context, expr);
1806
+ CleanupIllFormedExpressionRAII cleanup (expr);
1829
1807
ExprCleaner cleanup2 (expr);
1830
1808
1831
1809
// Verify that a purpose was specified if a convertType was. Note that it is
@@ -1940,7 +1918,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
1940
1918
1941
1919
// Construct a constraint system from this expression.
1942
1920
ConstraintSystem cs (*this , dc, ConstraintSystemFlags::AllowFixes);
1943
- CleanupIllFormedExpressionRAII cleanup (Context, expr);
1921
+ CleanupIllFormedExpressionRAII cleanup (expr);
1944
1922
1945
1923
// Attempt to solve the constraint system.
1946
1924
SmallVector<Solution, 4 > viable;
@@ -2035,7 +2013,7 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
2035
2013
// If the previous checking gives the expr error type,
2036
2014
// clear the result and re-check.
2037
2015
{
2038
- CleanupIllFormedExpressionRAII cleanup (Context, expr);
2016
+ CleanupIllFormedExpressionRAII cleanup (expr);
2039
2017
2040
2018
const Type originalType = expr->getType ();
2041
2019
if (originalType && originalType->hasError ())
@@ -2058,7 +2036,7 @@ bool TypeChecker::typeCheckCompletionSequence(Expr *&expr, DeclContext *DC) {
2058
2036
2059
2037
// Construct a constraint system from this expression.
2060
2038
ConstraintSystem CS (*this , DC, ConstraintSystemFlags::AllowFixes);
2061
- CleanupIllFormedExpressionRAII cleanup (Context, expr);
2039
+ CleanupIllFormedExpressionRAII cleanup (expr);
2062
2040
2063
2041
auto *SE = cast<SequenceExpr>(expr);
2064
2042
assert (SE->getNumElements () >= 3 );
@@ -2135,7 +2113,7 @@ bool TypeChecker::typeCheckExpressionShallow(Expr *&expr, DeclContext *dc) {
2135
2113
2136
2114
// Construct a constraint system from this expression.
2137
2115
ConstraintSystem cs (*this , dc, ConstraintSystemFlags::AllowFixes);
2138
- CleanupIllFormedExpressionRAII cleanup (Context, expr);
2116
+ CleanupIllFormedExpressionRAII cleanup (expr);
2139
2117
if (auto generatedExpr = cs.generateConstraintsShallow (expr))
2140
2118
expr = generatedExpr;
2141
2119
else
@@ -3001,7 +2979,7 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
3001
2979
// TODO: need to add kind arg?
3002
2980
// Construct a constraint system from this expression.
3003
2981
ConstraintSystem cs (*this , dc, ConstraintSystemFlags::AllowFixes);
3004
- CleanupIllFormedExpressionRAII cleanup (Context, expr);
2982
+ CleanupIllFormedExpressionRAII cleanup (expr);
3005
2983
3006
2984
// If there is a type that we're expected to convert to, add the conversion
3007
2985
// constraint.
0 commit comments