Skip to content

Commit 80a2eee

Browse files
committed
[Diagnostics] Remove a few special cases of printing 'any' for specific
error messages.
1 parent 12459cf commit 80a2eee

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,8 +2454,8 @@ ERROR(protocol_composition_one_class,none,
24542454
"contains class %1", (Type, Type))
24552455

24562456
ERROR(requires_conformance_nonprotocol,none,
2457-
"type %0 constrained to non-protocol, non-class type '%1'",
2458-
(Type, StringRef))
2457+
"type %0 constrained to non-protocol, non-class type %1",
2458+
(Type, Type))
24592459
NOTE(requires_conformance_nonprotocol_fixit,none,
24602460
"use '%0 == %1' to require '%0' to be '%1'",
24612461
(StringRef, StringRef))
@@ -2776,9 +2776,9 @@ WARNING(anyobject_class_inheritance_deprecated,Deprecation,
27762776
ERROR(multiple_inheritance,none,
27772777
"multiple inheritance from classes %0 and %1", (Type, Type))
27782778
ERROR(inheritance_from_non_protocol_or_class,none,
2779-
"inheritance from non-protocol, non-class type '%0'", (StringRef))
2779+
"inheritance from non-protocol, non-class type %0", (Type))
27802780
ERROR(inheritance_from_non_protocol,none,
2781-
"inheritance from non-protocol type '%0'", (StringRef))
2781+
"inheritance from non-protocol type %0", (Type))
27822782
ERROR(inheritance_from_anyobject,none,
27832783
"only protocols can inherit from 'AnyObject'", ())
27842784
ERROR(inheritance_from_parameterized_protocol,none,

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6307,16 +6307,8 @@ GenericSignatureBuilder::finalize(TypeArrayView<GenericTypeParamType> genericPar
63076307
auto source = constraint.source;
63086308
auto loc = source->getLoc();
63096309

6310-
// FIXME: The constraint string is printed directly here because
6311-
// the current default is to not print `any` for existential
6312-
// types, but this error message is super confusing without `any`
6313-
// if the user wrote it explicitly.
6314-
PrintOptions options;
6315-
options.PrintExplicitAny = true;
6316-
auto constraintString = constraintType.getString(options);
6317-
63186310
Diags.diagnose(loc, diag::requires_conformance_nonprotocol,
6319-
subjectType, constraintString);
6311+
subjectType, constraintType);
63206312

63216313
auto getNameWithoutSelf = [&](std::string subjectTypeName) {
63226314
std::string selfSubstring = "Self.";
@@ -6331,10 +6323,12 @@ GenericSignatureBuilder::finalize(TypeArrayView<GenericTypeParamType> genericPar
63316323
if (allowConcreteGenericParams ||
63326324
(subjectType->is<DependentMemberType>() &&
63336325
!source->isProtocolRequirement())) {
6334-
auto subjectTypeName = subjectType.getString();
6326+
auto options = PrintOptions::forDiagnosticArguments();
6327+
auto subjectTypeName = subjectType.getString(options);
63356328
auto subjectTypeNameWithoutSelf = getNameWithoutSelf(subjectTypeName);
63366329
Diags.diagnose(loc, diag::requires_conformance_nonprotocol_fixit,
6337-
subjectTypeNameWithoutSelf, constraintString)
6330+
subjectTypeNameWithoutSelf,
6331+
constraintType.getString(options))
63386332
.fixItReplace(loc, " == ");
63396333
}
63406334
}

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,8 @@ bool swift::rewriting::diagnoseRequirementErrors(
547547
if (subjectType->hasError() || constraint->hasError())
548548
break;
549549

550-
// FIXME: The constraint string is printed directly here because
551-
// the current default is to not print `any` for existential
552-
// types, but this error message is super confusing without `any`
553-
// if the user wrote it explicitly.
554-
PrintOptions options;
555-
options.PrintExplicitAny = true;
556-
auto constraintString = constraint.getString(options);
557-
558550
ctx.Diags.diagnose(loc, diag::requires_conformance_nonprotocol,
559-
subjectType, constraintString);
551+
subjectType, constraint);
560552
diagnosedError = true;
561553

562554
auto getNameWithoutSelf = [&](std::string subjectTypeName) {
@@ -570,10 +562,12 @@ bool swift::rewriting::diagnoseRequirementErrors(
570562
};
571563

572564
if (allowConcreteGenericParams) {
573-
auto subjectTypeName = subjectType.getString();
565+
auto options = PrintOptions::forDiagnosticArguments();
566+
auto subjectTypeName = subjectType.getString(options);
574567
auto subjectTypeNameWithoutSelf = getNameWithoutSelf(subjectTypeName);
575568
ctx.Diags.diagnose(loc, diag::requires_conformance_nonprotocol_fixit,
576-
subjectTypeNameWithoutSelf, constraintString)
569+
subjectTypeNameWithoutSelf,
570+
constraint.getString(options))
577571
.fixItReplace(loc, " == ");
578572
}
579573

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,19 +335,11 @@ static void checkInheritanceClause(
335335
}
336336
}
337337

338-
// FIXME: The inherited type is printed directly here because
339-
// the current default is to not print `any` for existential
340-
// types, but this error message is super confusing without `any`
341-
// if the user wrote it explicitly.
342-
PrintOptions options;
343-
options.PrintExplicitAny = true;
344-
auto inheritedTyString = inheritedTy.getString(options);
345-
346338
// We can't inherit from a non-class, non-protocol type.
347339
decl->diagnose(canHaveSuperclass
348340
? diag::inheritance_from_non_protocol_or_class
349341
: diag::inheritance_from_non_protocol,
350-
inheritedTyString);
342+
inheritedTy);
351343
// FIXME: Note pointing to the declaration 'inheritedTy' references?
352344
}
353345
}

0 commit comments

Comments
 (0)