Skip to content

Commit abfd19c

Browse files
committed
[Constraint solver] Update LiteralExpr::shallowClone to set types in type map.
It was getting types from the type map, but not setting them in it.
1 parent 041a25e commit abfd19c

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ class LiteralExpr : public Expr {
790790
// Make an exact copy of this one AST node.
791791
LiteralExpr *
792792
shallowClone(ASTContext &Ctx,
793+
llvm::function_ref<void(Expr *, Type)> setType,
793794
llvm::function_ref<Type(const Expr *)> getType) const;
794795

795796
static bool classof(const Expr *E) {

lib/AST/Expr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,8 @@ shallowCloneImpl(const ObjectLiteralExpr *E, ASTContext &Ctx,
930930

931931
// Make an exact copy of this AST node.
932932
LiteralExpr *LiteralExpr::shallowClone(
933-
ASTContext &Ctx, llvm::function_ref<Type(const Expr *)> getType) const {
933+
ASTContext &Ctx, llvm::function_ref<void(Expr *, Type)> setType,
934+
llvm::function_ref<Type(const Expr *)> getType) const {
934935
LiteralExpr *Result = nullptr;
935936
switch (getKind()) {
936937
default: llvm_unreachable("Unknown literal type!");
@@ -950,7 +951,7 @@ LiteralExpr *LiteralExpr::shallowClone(
950951
#undef DISPATCH_CLONE
951952
}
952953

953-
Result->setType(getType(this));
954+
setType(Result, getType(this));
954955
Result->setImplicit(isImplicit());
955956
return Result;
956957
}

lib/Sema/CSApply.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5980,13 +5980,18 @@ Expr *ExprRewriter::convertLiteral(Expr *literal,
59805980
return cs.getType(E);
59815981
};
59825982

5983+
auto setType = [&](Expr *E, Type Ty) {
5984+
cs.setType(E, Ty);
5985+
};
5986+
59835987
// If coercing a literal to an unresolved type, we don't try to look up the
59845988
// witness members, just do it.
59855989
if (type->is<UnresolvedType>()) {
59865990
// Instead of updating the literal expr in place, allocate a new node. This
59875991
// avoids issues where Builtin types end up on expr nodes and pollute
59885992
// diagnostics.
5989-
literal = cast<LiteralExpr>(literal)->shallowClone(tc.Context, getType);
5993+
literal = cast<LiteralExpr>(literal)->shallowClone(tc.Context, setType,
5994+
getType);
59905995

59915996
// The literal expression has this type.
59925997
cs.setType(literal, type);
@@ -6021,7 +6026,8 @@ Expr *ExprRewriter::convertLiteral(Expr *literal,
60216026
// Instead of updating the literal expr in place, allocate a new node. This
60226027
// avoids issues where Builtin types end up on expr nodes and pollute
60236028
// diagnostics.
6024-
literal = cast<LiteralExpr>(literal)->shallowClone(tc.Context, getType);
6029+
literal = cast<LiteralExpr>(literal)->shallowClone(tc.Context, setType,
6030+
getType);
60256031

60266032
// The literal expression has this type.
60276033
cs.setType(literal, argType);
@@ -6124,13 +6130,18 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
61246130
return cs.getType(E);
61256131
};
61266132

6133+
auto setType = [&](Expr *E, Type Ty) {
6134+
cs.setType(E, Ty);
6135+
};
6136+
61276137
// If coercing a literal to an unresolved type, we don't try to look up the
61286138
// witness members, just do it.
61296139
if (type->is<UnresolvedType>()) {
61306140
// Instead of updating the literal expr in place, allocate a new node. This
61316141
// avoids issues where Builtin types end up on expr nodes and pollute
61326142
// diagnostics.
6133-
literal = cast<LiteralExpr>(literal)->shallowClone(tc.Context, getType);
6143+
literal = cast<LiteralExpr>(literal)->shallowClone(tc.Context, setType,
6144+
getType);
61346145

61356146
// The literal expression has this type.
61366147
cs.setType(literal, type);

0 commit comments

Comments
 (0)