[AST] Introduce UnresolvedMemberChainResultExpr

Introduce a new expression type for representing the result of an unresolved member chain. Use this expression type instead of an implicit ParenExpr for giving unresolved member chain result types representation in the AST during type checking.
This commit is contained in:
Frederick Kellison-Linn
2020-07-31 18:02:26 -04:00
parent 4e9b7b20db
commit f5845666e6
6 changed files with 46 additions and 31 deletions

View File

@@ -3259,21 +3259,22 @@ namespace {
}
Expr *visitParenExpr(ParenExpr *expr) {
// If this was an implicit ParenExpr inserted to give an unresolved member
// chain result type visibility in the AST (see
// ConstraintWalker::walkToExprPost), remove it from the AST now that we
// have a solution.
if (expr->isUnresolvedMemberChainPlaceholder()) {
auto *subExpr = expr->getSubExpr();
auto type = simplifyType(cs.getType(expr));
subExpr = coerceToType(subExpr, type, cs.getConstraintLocator(subExpr));
cs.setType(subExpr, type);
return subExpr;
}
return simplifyExprType(expr);
}
Expr *visitUnresolvedMemberChainResultExpr(
UnresolvedMemberChainResultExpr *expr) {
// Since this expression only exists to give the result type of an
// unresolved member chain visibility in the AST, remove it from the AST
// now that we have a solution and coerce the subexpr to the resulting
// type.
auto *subExpr = expr->getSubExpr();
auto type = simplifyType(cs.getType(expr));
subExpr = coerceToType(subExpr, type, cs.getConstraintLocator(subExpr));
cs.setType(subExpr, type);
return subExpr;
}
Expr *visitTupleExpr(TupleExpr *expr) {
return simplifyExprType(expr);
}