Skip to content

Commit 5ab6691

Browse files
committed
Drop the TypeChecker in maybeDiagnoseClassWithoutInitializers
1 parent 7993f2f commit 5ab6691

File tree

3 files changed

+28
-30
lines changed

3 files changed

+28
-30
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4574,8 +4574,7 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
45744574
/// Build a default initializer string for the given pattern.
45754575
///
45764576
/// This string is suitable for display in diagnostics.
4577-
static Optional<std::string> buildDefaultInitializerString(TypeChecker &tc,
4578-
DeclContext *dc,
4577+
static Optional<std::string> buildDefaultInitializerString(DeclContext *dc,
45794578
Pattern *pattern) {
45804579
switch (pattern->getKind()) {
45814580
#define REFUTABLE_PATTERN(Id, Parent) case PatternKind::Id:
@@ -4618,7 +4617,7 @@ static Optional<std::string> buildDefaultInitializerString(TypeChecker &tc,
46184617

46194618
case PatternKind::Paren: {
46204619
if (auto sub = buildDefaultInitializerString(
4621-
tc, dc, cast<ParenPattern>(pattern)->getSubPattern())) {
4620+
dc, cast<ParenPattern>(pattern)->getSubPattern())) {
46224621
return "(" + *sub + ")";
46234622
}
46244623

@@ -4629,7 +4628,7 @@ static Optional<std::string> buildDefaultInitializerString(TypeChecker &tc,
46294628
std::string result = "(";
46304629
bool first = true;
46314630
for (auto elt : cast<TuplePattern>(pattern)->getElements()) {
4632-
if (auto sub = buildDefaultInitializerString(tc, dc, elt.getPattern())) {
4631+
if (auto sub = buildDefaultInitializerString(dc, elt.getPattern())) {
46334632
if (first) {
46344633
first = false;
46354634
} else {
@@ -4647,21 +4646,21 @@ static Optional<std::string> buildDefaultInitializerString(TypeChecker &tc,
46474646

46484647
case PatternKind::Typed:
46494648
return buildDefaultInitializerString(
4650-
tc, dc, cast<TypedPattern>(pattern)->getSubPattern());
4649+
dc, cast<TypedPattern>(pattern)->getSubPattern());
46514650

46524651
case PatternKind::Var:
46534652
return buildDefaultInitializerString(
4654-
tc, dc, cast<VarPattern>(pattern)->getSubPattern());
4653+
dc, cast<VarPattern>(pattern)->getSubPattern());
46554654
}
46564655

46574656
llvm_unreachable("Unhandled PatternKind in switch.");
46584657
}
46594658

46604659
/// Diagnose a class that does not have any initializers.
4661-
static void diagnoseClassWithoutInitializers(TypeChecker &tc,
4662-
ClassDecl *classDecl) {
4663-
tc.diagnose(classDecl, diag::class_without_init,
4664-
classDecl->getDeclaredType());
4660+
static void diagnoseClassWithoutInitializers(ClassDecl *classDecl) {
4661+
ASTContext &C = classDecl->getASTContext();
4662+
C.Diags.diagnose(classDecl, diag::class_without_init,
4663+
classDecl->getDeclaredType());
46654664

46664665
// HACK: We've got a special case to look out for and diagnose specifically to
46674666
// improve the experience of seeing this, and mitigate some confusion.
@@ -4677,7 +4676,6 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
46774676
// listing the members that prevented initializer synthesis.
46784677
// TODO: Add a fixit along with this suggestion.
46794678
if (auto *superclassDecl = classDecl->getSuperclassDecl()) {
4680-
ASTContext &C = tc.Context;
46814679
auto *decodableProto = C.getProtocol(KnownProtocolKind::Decodable);
46824680
auto superclassType = superclassDecl->getDeclaredInterfaceType();
46834681
auto ref = TypeChecker::conformsToProtocol(
@@ -4708,9 +4706,9 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
47084706
// likely that the user forgot to override its encode(to:). In this case,
47094707
// we can produce a slightly different diagnostic to suggest doing so.
47104708
auto *encodableProto = C.getProtocol(KnownProtocolKind::Encodable);
4711-
auto ref =
4712-
tc.conformsToProtocol(superclassType, encodableProto, superclassDecl,
4713-
ConformanceCheckOptions(), SourceLoc());
4709+
auto ref = TypeChecker::conformsToProtocol(
4710+
superclassType, encodableProto, superclassDecl,
4711+
ConformanceCheckOptions(), SourceLoc());
47144712
if (ref) {
47154713
// We only want to produce this version of the diagnostic if the
47164714
// subclass doesn't directly implement encode(to:).
@@ -4721,7 +4719,7 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
47214719
diagName = diag::codable_suggest_overriding_init_here;
47224720
}
47234721

4724-
tc.diagnose(diagDest, diagName);
4722+
C.Diags.diagnose(diagDest, diagName);
47254723
}
47264724
}
47274725

@@ -4779,27 +4777,27 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
47794777
Optional<InFlightDiagnostic> diag;
47804778
switch (vars.size()) {
47814779
case 1:
4782-
diag.emplace(tc.diagnose(varLoc, diag::note_no_in_class_init_1,
4783-
vars[0]->getName()));
4780+
diag.emplace(C.Diags.diagnose(varLoc, diag::note_no_in_class_init_1,
4781+
vars[0]->getName()));
47844782
break;
47854783
case 2:
4786-
diag.emplace(tc.diagnose(varLoc, diag::note_no_in_class_init_2,
4787-
vars[0]->getName(), vars[1]->getName()));
4784+
diag.emplace(C.Diags.diagnose(varLoc, diag::note_no_in_class_init_2,
4785+
vars[0]->getName(), vars[1]->getName()));
47884786
break;
47894787
case 3:
4790-
diag.emplace(tc.diagnose(varLoc, diag::note_no_in_class_init_3plus,
4791-
vars[0]->getName(), vars[1]->getName(),
4792-
vars[2]->getName(), false));
4788+
diag.emplace(C.Diags.diagnose(varLoc, diag::note_no_in_class_init_3plus,
4789+
vars[0]->getName(), vars[1]->getName(),
4790+
vars[2]->getName(), false));
47934791
break;
47944792
default:
4795-
diag.emplace(tc.diagnose(varLoc, diag::note_no_in_class_init_3plus,
4796-
vars[0]->getName(), vars[1]->getName(),
4797-
vars[2]->getName(), true));
4793+
diag.emplace(C.Diags.diagnose(varLoc, diag::note_no_in_class_init_3plus,
4794+
vars[0]->getName(), vars[1]->getName(),
4795+
vars[2]->getName(), true));
47984796
break;
47994797
}
48004798

4801-
if (auto defaultValueSuggestion
4802-
= buildDefaultInitializerString(tc, classDecl, pattern))
4799+
if (auto defaultValueSuggestion =
4800+
buildDefaultInitializerString(classDecl, pattern))
48034801
diag->fixItInsertAfter(pattern->getEndLoc(),
48044802
" = " + *defaultValueSuggestion);
48054803
}
@@ -4837,5 +4835,5 @@ void TypeChecker::maybeDiagnoseClassWithoutInitializers(ClassDecl *classDecl) {
48374835
return;
48384836
}
48394837

4840-
diagnoseClassWithoutInitializers(*this, classDecl);
4838+
diagnoseClassWithoutInitializers(classDecl);
48414839
}

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
301301

302302
// Finally, we can check classes for missing initializers.
303303
if (auto *classDecl = dyn_cast<ClassDecl>(ntd))
304-
TC.maybeDiagnoseClassWithoutInitializers(classDecl);
304+
TypeChecker::maybeDiagnoseClassWithoutInitializers(classDecl);
305305
}
306306
}
307307
TC.ConformanceContexts.clear();

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ class TypeChecker final : public LazyResolver {
11111111
SubstOptions options = None);
11121112

11131113
/// Diagnose if the class has no designated initializers.
1114-
void maybeDiagnoseClassWithoutInitializers(ClassDecl *classDecl);
1114+
static void maybeDiagnoseClassWithoutInitializers(ClassDecl *classDecl);
11151115

11161116
///
11171117
/// Add any implicitly-defined constructors required for the given

0 commit comments

Comments
 (0)