Skip to content

Commit d07e317

Browse files
committed
[CodeSynthesis] Make sure that LazyInitializerExpr has a type
Currently when `LazyInitializerExpr` is added to the AST it's not given an explicit type. Because of that constraint solver silently fails in contraint generator without diagnostic. But since sub-expression associated with `LazyInitializerExpr` is already type-checked it makes sense to set its type explicitly.
1 parent 60e54db commit d07e317

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,8 +3885,8 @@ namespace {
38853885
}
38863886

38873887
Expr *visitLazyInitializerExpr(LazyInitializerExpr *expr) {
3888-
simplifyExprType(expr);
3889-
assert(expr->getType()->isEqual(expr->getSubExpr()->getType()));
3888+
expr = simplifyExprType(expr);
3889+
assert(cs.getType(expr)->isEqual(expr->getSubExpr()->getType()));
38903890
return expr;
38913891
}
38923892

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,9 @@ namespace {
29182918
}
29192919

29202920
Type visitLazyInitializerExpr(LazyInitializerExpr *expr) {
2921-
return expr->getType();
2921+
auto type = expr->getType();
2922+
assert(type && "LazyInitializerExpr should always have type set");
2923+
return type;
29222924
}
29232925

29242926
Type visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) {

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,9 @@ static void synthesizeLazyGetterBody(AbstractFunctionDecl *fn, void *context) {
12941294
// FIXME: we should really have stronger invariants than this. Leaving it
12951295
// unwrapped may expose both expressions to naive walkers
12961296
if (wasInitializerChecked) {
1297+
auto initType = InitValue->getType();
12971298
InitValue = new (Ctx) LazyInitializerExpr(InitValue);
1299+
InitValue->setType(initType);
12981300
}
12991301

13001302
Pattern *Tmp2PBDPattern = new (Ctx) NamedPattern(Tmp2VD, /*implicit*/true);

0 commit comments

Comments
 (0)