Skip to content

Commit ecb7b8c

Browse files
committed
Make convertToType a utility
1 parent 32e6846 commit ecb7b8c

File tree

7 files changed

+15
-12
lines changed

7 files changed

+15
-12
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3531,7 +3531,7 @@ namespace {
35313531

35323532
solution.setExprTypes(sub);
35333533

3534-
if (cs.getTypeChecker().convertToType(sub, toType, cs.DC))
3534+
if (TypeChecker::convertToType(sub, toType, cs.DC))
35353535
return nullptr;
35363536

35373537
cs.cacheExprTypes(sub);

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3626,7 +3626,7 @@ namespace {
36263626
if (auto keyPath = dyn_cast<KeyPathExpr>(expr)) {
36273627
if (keyPath->isObjC()) {
36283628
auto &cs = CG.getConstraintSystem();
3629-
(void)cs.getTypeChecker().checkObjCKeyPathExpr(cs.DC, keyPath);
3629+
(void)TypeChecker::checkObjCKeyPathExpr(cs.DC, keyPath);
36303630
}
36313631
}
36323632

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,7 +3451,8 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
34513451
cs.addConstraint(ConstraintKind::Conversion, expr->getType(), type,
34523452
cs.getConstraintLocator(expr));
34533453

3454-
if (getLangOpts().DebugConstraintSolver) {
3454+
auto &Context = dc->getASTContext();
3455+
if (Context.LangOpts.DebugConstraintSolver) {
34553456
auto &log = Context.TypeCheckerDebug->getStream();
34563457
log << "---Initial constraints for the given expression---\n";
34573458
expr->dump(log);
@@ -3467,7 +3468,7 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
34673468
}
34683469

34693470
auto &solution = viable[0];
3470-
if (getLangOpts().DebugConstraintSolver) {
3471+
if (Context.LangOpts.DebugConstraintSolver) {
34713472
auto &log = Context.TypeCheckerDebug->getStream();
34723473
log << "---Solution---\n";
34733474
solution.dump(log);
@@ -3485,7 +3486,7 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc,
34853486

34863487
solution.setExprTypes(expr);
34873488

3488-
if (getLangOpts().DebugConstraintSolver) {
3489+
if (Context.LangOpts.DebugConstraintSolver) {
34893490
auto &log = Context.TypeCheckerDebug->getStream();
34903491
log << "---Type-checked expression---\n";
34913492
result->dump(log);

lib/Sema/TypeCheckExprObjC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Optional<Type> TypeChecker::checkObjCKeyPathExpr(DeclContext *dc,
3030
if (expr->getObjCStringLiteralExpr() && !requireResultType) return None;
3131

3232
// ObjC #keyPath only makes sense when we have the Objective-C runtime.
33-
auto &diags = dc->getASTContext().Diags;
33+
auto &Context = dc->getASTContext();
34+
auto &diags = Context.Diags;
3435
if (!Context.LangOpts.EnableObjCInterop) {
3536
diags.diagnose(expr->getLoc(), diag::expr_keypath_no_objc_runtime);
3637

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
832832
->getParams()[0].getPlainType().subst(witness.getSubstitutions());
833833

834834
// Necessary type coersion for method application.
835-
if (TC.convertToType(sequence, newSequenceType, DC, None)) {
835+
if (TypeChecker::convertToType(sequence, newSequenceType, DC, None)) {
836836
return nullptr;
837837
}
838838
S->setSequence(sequence);

lib/Sema/TypeChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@ static Optional<Type> getTypeOfCompletionContextExpr(
639639
case CompletionTypeCheckKind::KeyPath:
640640
referencedDecl = nullptr;
641641
if (auto keyPath = dyn_cast<KeyPathExpr>(parsedExpr))
642-
return TC.checkObjCKeyPathExpr(DC, keyPath, /*requireResultType=*/true);
642+
return TypeChecker::checkObjCKeyPathExpr(DC, keyPath,
643+
/*requireResultType=*/true);
643644

644645
return None;
645646
}

lib/Sema/TypeChecker.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,8 @@ class TypeChecker final {
11991199
/// Check the key-path expression.
12001200
///
12011201
/// Returns the type of the last component of the key-path.
1202-
Optional<Type> checkObjCKeyPathExpr(DeclContext *dc, KeyPathExpr *expr,
1203-
bool requireResultType = false);
1202+
static Optional<Type> checkObjCKeyPathExpr(DeclContext *dc, KeyPathExpr *expr,
1203+
bool requireResultType = false);
12041204

12051205
/// Type check whether the given type declaration includes members of
12061206
/// unsupported recursive value types.
@@ -1397,8 +1397,8 @@ class TypeChecker final {
13971397
/// from where the toType is derived, so that we can deliver better fixit.
13981398
///
13991399
/// \returns true if an error occurred, false otherwise.
1400-
bool convertToType(Expr *&expr, Type type, DeclContext *dc,
1401-
Optional<Pattern*> typeFromPattern = None);
1400+
static bool convertToType(Expr *&expr, Type type, DeclContext *dc,
1401+
Optional<Pattern*> typeFromPattern = None);
14021402

14031403
/// Coerce the given expression to materializable type, if it
14041404
/// isn't already.

0 commit comments

Comments
 (0)