@@ -4574,8 +4574,7 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
4574
4574
// / Build a default initializer string for the given pattern.
4575
4575
// /
4576
4576
// / 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,
4579
4578
Pattern *pattern) {
4580
4579
switch (pattern->getKind ()) {
4581
4580
#define REFUTABLE_PATTERN (Id, Parent ) case PatternKind::Id:
@@ -4618,7 +4617,7 @@ static Optional<std::string> buildDefaultInitializerString(TypeChecker &tc,
4618
4617
4619
4618
case PatternKind::Paren: {
4620
4619
if (auto sub = buildDefaultInitializerString (
4621
- tc, dc, cast<ParenPattern>(pattern)->getSubPattern ())) {
4620
+ dc, cast<ParenPattern>(pattern)->getSubPattern ())) {
4622
4621
return " (" + *sub + " )" ;
4623
4622
}
4624
4623
@@ -4629,7 +4628,7 @@ static Optional<std::string> buildDefaultInitializerString(TypeChecker &tc,
4629
4628
std::string result = " (" ;
4630
4629
bool first = true ;
4631
4630
for (auto elt : cast<TuplePattern>(pattern)->getElements ()) {
4632
- if (auto sub = buildDefaultInitializerString (tc, dc, elt.getPattern ())) {
4631
+ if (auto sub = buildDefaultInitializerString (dc, elt.getPattern ())) {
4633
4632
if (first) {
4634
4633
first = false ;
4635
4634
} else {
@@ -4647,21 +4646,21 @@ static Optional<std::string> buildDefaultInitializerString(TypeChecker &tc,
4647
4646
4648
4647
case PatternKind::Typed:
4649
4648
return buildDefaultInitializerString (
4650
- tc, dc, cast<TypedPattern>(pattern)->getSubPattern ());
4649
+ dc, cast<TypedPattern>(pattern)->getSubPattern ());
4651
4650
4652
4651
case PatternKind::Var:
4653
4652
return buildDefaultInitializerString (
4654
- tc, dc, cast<VarPattern>(pattern)->getSubPattern ());
4653
+ dc, cast<VarPattern>(pattern)->getSubPattern ());
4655
4654
}
4656
4655
4657
4656
llvm_unreachable (" Unhandled PatternKind in switch." );
4658
4657
}
4659
4658
4660
4659
// / 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 ());
4665
4664
4666
4665
// HACK: We've got a special case to look out for and diagnose specifically to
4667
4666
// improve the experience of seeing this, and mitigate some confusion.
@@ -4677,7 +4676,6 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
4677
4676
// listing the members that prevented initializer synthesis.
4678
4677
// TODO: Add a fixit along with this suggestion.
4679
4678
if (auto *superclassDecl = classDecl->getSuperclassDecl ()) {
4680
- ASTContext &C = tc.Context ;
4681
4679
auto *decodableProto = C.getProtocol (KnownProtocolKind::Decodable);
4682
4680
auto superclassType = superclassDecl->getDeclaredInterfaceType ();
4683
4681
auto ref = TypeChecker::conformsToProtocol (
@@ -4708,9 +4706,9 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
4708
4706
// likely that the user forgot to override its encode(to:). In this case,
4709
4707
// we can produce a slightly different diagnostic to suggest doing so.
4710
4708
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 ());
4714
4712
if (ref) {
4715
4713
// We only want to produce this version of the diagnostic if the
4716
4714
// subclass doesn't directly implement encode(to:).
@@ -4721,7 +4719,7 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
4721
4719
diagName = diag::codable_suggest_overriding_init_here;
4722
4720
}
4723
4721
4724
- tc .diagnose (diagDest, diagName);
4722
+ C. Diags .diagnose (diagDest, diagName);
4725
4723
}
4726
4724
}
4727
4725
@@ -4779,27 +4777,27 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
4779
4777
Optional<InFlightDiagnostic> diag;
4780
4778
switch (vars.size ()) {
4781
4779
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 ()));
4784
4782
break ;
4785
4783
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 ()));
4788
4786
break ;
4789
4787
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 ));
4793
4791
break ;
4794
4792
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 ));
4798
4796
break ;
4799
4797
}
4800
4798
4801
- if (auto defaultValueSuggestion
4802
- = buildDefaultInitializerString (tc, classDecl, pattern))
4799
+ if (auto defaultValueSuggestion =
4800
+ buildDefaultInitializerString (classDecl, pattern))
4803
4801
diag->fixItInsertAfter (pattern->getEndLoc (),
4804
4802
" = " + *defaultValueSuggestion);
4805
4803
}
@@ -4837,5 +4835,5 @@ void TypeChecker::maybeDiagnoseClassWithoutInitializers(ClassDecl *classDecl) {
4837
4835
return ;
4838
4836
}
4839
4837
4840
- diagnoseClassWithoutInitializers (* this , classDecl);
4838
+ diagnoseClassWithoutInitializers (classDecl);
4841
4839
}
0 commit comments