Skip to content

Commit 376e19e

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. (cherry picked from commit 20b7c2a)
1 parent 6373a5d commit 376e19e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,8 +3912,9 @@ namespace {
39123912
}
39133913

39143914
Expr *visitLazyInitializerExpr(LazyInitializerExpr *expr) {
3915-
simplifyExprType(expr);
3916-
assert(expr->getType()->isEqual(expr->getSubExpr()->getType()));
3915+
// Since `LazyInitializerExpr` should always have a type set,
3916+
// there is no need to do anything here.
3917+
assert(cs.getType(expr)->isEqual(expr->getSubExpr()->getType()));
39173918
return expr;
39183919
}
39193920

lib/Sema/CSGen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,9 @@ namespace {
29242924
}
29252925

29262926
Type visitLazyInitializerExpr(LazyInitializerExpr *expr) {
2927-
return expr->getType();
2927+
auto type = expr->getType();
2928+
assert(type && "LazyInitializerExpr should always have type set");
2929+
return type;
29282930
}
29292931

29302932
Type visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) {

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,9 @@ static void synthesizeLazyGetterBody(TypeChecker &TC, AccessorDecl *Get,
13231323
// FIXME: we should really have stronger invariants than this. Leaving it
13241324
// unwrapped may expose both expressions to naive walkers
13251325
if (wasInitializerChecked) {
1326+
auto initType = InitValue->getType();
13261327
InitValue = new (Ctx) LazyInitializerExpr(InitValue);
1328+
InitValue->setType(initType);
13271329
}
13281330

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

0 commit comments

Comments
 (0)