Skip to content

Commit c4a0585

Browse files
committed
Make getObjectLiteralConstructorName a utility
1 parent 51b1747 commit c4a0585

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,13 +3531,14 @@ bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
35313531
auto protocol = TypeChecker::getLiteralProtocol(CS.getASTContext(), E);
35323532
if (!protocol)
35333533
return false;
3534-
DeclName constrName = TC.getObjectLiteralConstructorName(E);
3534+
auto constrName =
3535+
TypeChecker::getObjectLiteralConstructorName(CS.getASTContext(), E);
35353536
assert(constrName);
35363537
auto *constr = dyn_cast_or_null<ConstructorDecl>(
35373538
protocol->getSingleRequirement(constrName));
35383539
if (!constr)
35393540
return false;
3540-
auto paramType = TC.getObjectLiteralParameterType(E, constr);
3541+
auto paramType = TypeChecker::getObjectLiteralParameterType(E, constr);
35413542
if (!typeCheckChildIndependently(
35423543
E->getArg(), paramType, CTP_CallArgument))
35433544
return true;

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,10 +1260,10 @@ namespace {
12601260
if (expr->getType())
12611261
return expr->getType();
12621262

1263-
auto &tc = CS.getTypeChecker();
1263+
auto &de = CS.getASTContext().Diags;
12641264
auto protocol = TypeChecker::getLiteralProtocol(CS.getASTContext(), expr);
12651265
if (!protocol) {
1266-
tc.diagnose(expr->getLoc(), diag::use_unknown_object_literal_protocol,
1266+
de.diagnose(expr->getLoc(), diag::use_unknown_object_literal_protocol,
12671267
expr->getLiteralKindPlainName());
12681268
return nullptr;
12691269
}
@@ -1282,15 +1282,18 @@ namespace {
12821282
// all the redundant stuff about literals (leaving e.g. "red:").
12831283
// Constraint application will quietly rewrite the type of 'args' to
12841284
// use the right labels before forming the call to the initializer.
1285-
DeclName constrName = tc.getObjectLiteralConstructorName(expr);
1285+
auto constrName =
1286+
TypeChecker::getObjectLiteralConstructorName(CS.getASTContext(),
1287+
expr);
12861288
assert(constrName);
12871289
auto *constr = dyn_cast_or_null<ConstructorDecl>(
12881290
protocol->getSingleRequirement(constrName));
12891291
if (!constr) {
1290-
tc.diagnose(protocol, diag::object_literal_broken_proto);
1292+
de.diagnose(protocol, diag::object_literal_broken_proto);
12911293
return nullptr;
12921294
}
1293-
auto constrParamType = tc.getObjectLiteralParameterType(expr, constr);
1295+
auto constrParamType =
1296+
TypeChecker::getObjectLiteralParameterType(expr, constr);
12941297

12951298
// Extract the arguments.
12961299
SmallVector<AnyFunctionType::Param, 8> args;

lib/Sema/TypeChecker.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ ProtocolDecl *TypeChecker::getLiteralProtocol(ASTContext &Context, Expr *expr) {
161161
return nullptr;
162162
}
163163

164-
DeclName TypeChecker::getObjectLiteralConstructorName(ObjectLiteralExpr *expr) {
164+
DeclName TypeChecker::getObjectLiteralConstructorName(ASTContext &Context,
165+
ObjectLiteralExpr *expr) {
165166
switch (expr->getLiteralKind()) {
166167
case ObjectLiteralExpr::colorLiteral: {
167168
return DeclName(Context, DeclBaseName::createConstructor(),
@@ -200,6 +201,7 @@ Type TypeChecker::getObjectLiteralParameterType(ObjectLiteralExpr *expr,
200201
newParams.append(params.begin(), params.end());
201202

202203
auto replace = [&](StringRef replacement) -> Type {
204+
auto &Context = ctor->getASTContext();
203205
newParams[0] = AnyFunctionType::Param(newParams[0].getPlainType(),
204206
Context.getIdentifier(replacement),
205207
newParams[0].getParameterFlags());

lib/Sema/TypeChecker.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,10 +1648,11 @@ class TypeChecker final {
16481648
/// expression does not have an associated literal protocol.
16491649
static ProtocolDecl *getLiteralProtocol(ASTContext &ctx, Expr *expr);
16501650

1651-
DeclName getObjectLiteralConstructorName(ObjectLiteralExpr *expr);
1651+
static DeclName getObjectLiteralConstructorName(ASTContext &ctx,
1652+
ObjectLiteralExpr *expr);
16521653

1653-
Type getObjectLiteralParameterType(ObjectLiteralExpr *expr,
1654-
ConstructorDecl *ctor);
1654+
static Type getObjectLiteralParameterType(ObjectLiteralExpr *expr,
1655+
ConstructorDecl *ctor);
16551656

16561657
/// Get the module appropriate for looking up standard library types.
16571658
///

0 commit comments

Comments
 (0)