Skip to content

Commit 65aeb4a

Browse files
committed
[CSSolver] Add support for TypeJoinExpr
1 parent b95103c commit 65aeb4a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,10 @@ namespace {
52245224
return E;
52255225
}
52265226

5227+
Expr *visitTypeJoinExpr(TypeJoinExpr *E) {
5228+
llvm_unreachable("already type-checked?");
5229+
}
5230+
52275231
/// Interface for ExprWalker
52285232
void walkToExprPre(Expr *expr) {
52295233
// If we have an apply, make a note of its callee locator prior to

lib/Sema/CSGen.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,6 +3524,26 @@ namespace {
35243524
return tv;
35253525
}
35263526

3527+
Type visitTypeJoinExpr(TypeJoinExpr *expr) {
3528+
auto *locator = CS.getConstraintLocator(expr);
3529+
SmallVector<std::pair<Type, ConstraintLocator *>, 4> elements;
3530+
elements.reserve(expr->getNumElements());
3531+
3532+
for (auto *element : expr->getElements()) {
3533+
elements.emplace_back(CS.getType(element),
3534+
CS.getConstraintLocator(element));
3535+
}
3536+
3537+
auto resultTy = CS.getType(expr->getVar());
3538+
// The type of a join expression is obtained by performing
3539+
// a "join-meet" operation on deduced types of its elements
3540+
// and the underlying variable.
3541+
auto joinedTy = CS.addJoinConstraint(locator, elements);
3542+
3543+
CS.addConstraint(ConstraintKind::Equal, resultTy, joinedTy, locator);
3544+
return resultTy;
3545+
}
3546+
35273547
static bool isTriggerFallbackDiagnosticBuiltin(UnresolvedDotExpr *UDE,
35283548
ASTContext &Context) {
35293549
auto *DRE = dyn_cast<DeclRefExpr>(UDE->getBase());

0 commit comments

Comments
 (0)