Skip to content

Commit 8edb57c

Browse files
authored
Merge pull request swiftlang#75667 from ahoppen/build-issues-live-issues
[Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
2 parents 2925d46 + 6610439 commit 8edb57c

File tree

143 files changed

+889
-690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+889
-690
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,9 +2944,8 @@ NOTE(inherited_protocol_does_not_conform,none,
29442944
"type %0 does not conform to inherited protocol %1", (Type, Type))
29452945
NOTE(no_witnesses,none,
29462946
"protocol requires "
2947-
"%select{initializer %1|function %1|property %1|subscript}0 with type %2"
2948-
"%select{|; add a stub for conformance}3",
2949-
(RequirementKind, const ValueDecl *, WitnessType, bool))
2947+
"%select{initializer %1|function %1|property %1|subscript}0 with type %2",
2948+
(RequirementKind, const ValueDecl *, WitnessType))
29502949
NOTE(missing_witnesses_general,none, "add stubs for conformance",
29512950
())
29522951
NOTE(ambiguous_witnesses,none,
@@ -2960,11 +2959,10 @@ NOTE(ambiguous_witnesses_wrong_name,none,
29602959
"subscript operators}0 with type %2",
29612960
(RequirementKind, const ValueDecl *, WitnessType))
29622961
NOTE(no_witnesses_type,none,
2963-
"protocol requires nested type %0; add nested type %0 for conformance",
2962+
"protocol requires nested type %0",
29642963
(const AssociatedTypeDecl *))
29652964
NOTE(no_witnesses_type_tuple,none,
2966-
"protocol requires nested type %0; add type alias %0 with underlying type %1 "
2967-
"for conformance",
2965+
"protocol requires nested type %0",
29682966
(const AssociatedTypeDecl *, Type))
29692967
NOTE(default_associated_type_unsatisfied_conformance,none,
29702968
"default type %0 for associated type %1 (from protocol %2) "

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,11 +3474,6 @@ bool ContextualFailure::tryProtocolConformanceFixIt(
34743474
conformanceDiag.fixItInsert(nameEndLoc, ": " + protoString);
34753475
}
34763476

3477-
// Emit fix-its to insert requirement stubs if we're in editor mode.
3478-
if (!getASTContext().LangOpts.DiagnosticsEditorMode) {
3479-
return true;
3480-
}
3481-
34823477
{
34833478
llvm::SmallString<128> Text;
34843479
llvm::raw_svector_ostream SS(Text);

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@ ValueDecl *DerivedConformance::deriveEncodable(ValueDecl *requirement) {
21162116
ConformanceDecl->diagnose(diag::type_does_not_conform,
21172117
Nominal->getDeclaredType(), getProtocolType());
21182118
requirement->diagnose(diag::no_witnesses, diag::RequirementKind::Func,
2119-
requirement, getProtocolType(), /*AddFixIt=*/false);
2119+
requirement, getProtocolType());
21202120

21212121
return nullptr;
21222122
}
@@ -2146,8 +2146,9 @@ ValueDecl *DerivedConformance::deriveDecodable(ValueDecl *requirement) {
21462146
if (!canSynthesize(*this, requirement, delayedNotes)) {
21472147
ConformanceDecl->diagnose(diag::type_does_not_conform,
21482148
Nominal->getDeclaredType(), getProtocolType());
2149-
requirement->diagnose(diag::no_witnesses, diag::RequirementKind::Constructor,
2150-
requirement, getProtocolType(), /*AddFixIt=*/false);
2149+
requirement->diagnose(diag::no_witnesses,
2150+
diag::RequirementKind::Constructor, requirement,
2151+
getProtocolType());
21512152

21522153
return nullptr;
21532154
}

lib/Sema/DerivedConformanceDifferentiable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ ValueDecl *DerivedConformance::deriveDifferentiable(ValueDecl *requirement) {
638638
ConformanceDecl->diagnose(diag::type_does_not_conform,
639639
Nominal->getDeclaredType(), getProtocolType());
640640
requirement->diagnose(diag::no_witnesses,
641-
getProtocolRequirementKind(requirement),
642-
requirement, getProtocolType(), /*AddFixIt=*/false);
641+
getProtocolRequirementKind(requirement), requirement,
642+
getProtocolType());
643643

644644
// If derivation is possible, cancel the diagnostic and perform derivation.
645645
if (canDeriveDifferentiable(Nominal, getConformanceContext(), requirement)) {

lib/Sema/DerivedConformances.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -599,20 +599,18 @@ bool DerivedConformance::checkAndDiagnoseDisallowedContext(
599599
getProtocolType());
600600
Nominal->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
601601

602-
// In editor mode, try to insert a stub.
603-
if (Context.LangOpts.DiagnosticsEditorMode) {
604-
auto Extension = cast<ExtensionDecl>(getConformanceContext());
605-
auto FixitLocation = Extension->getBraces().Start;
606-
llvm::SmallString<128> Text;
607-
{
608-
llvm::raw_svector_ostream SS(Text);
609-
swift::printRequirementStub(synthesizing, Nominal,
610-
Nominal->getDeclaredType(),
611-
Extension->getStartLoc(), SS);
612-
if (!Text.empty()) {
613-
ConformanceDecl->diagnose(diag::missing_witnesses_general)
614-
.fixItInsertAfter(FixitLocation, Text.str());
615-
}
602+
// Try to insert a stub.
603+
auto Extension = cast<ExtensionDecl>(getConformanceContext());
604+
auto FixitLocation = Extension->getBraces().Start;
605+
llvm::SmallString<128> Text;
606+
{
607+
llvm::raw_svector_ostream SS(Text);
608+
swift::printRequirementStub(synthesizing, Nominal,
609+
Nominal->getDeclaredType(),
610+
Extension->getStartLoc(), SS);
611+
if (!Text.empty()) {
612+
ConformanceDecl->diagnose(diag::missing_witnesses_general)
613+
.fixItInsertAfter(FixitLocation, Text.str());
616614
}
617615
}
618616
return true;

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,11 +1644,10 @@ void swift::tryDiagnoseExecutorConformance(ASTContext &C,
16441644

16451645
if (missingRequirement) {
16461646
nominal->diagnose(diag::type_does_not_conform, nominalTy, proto->getDeclaredInterfaceType());
1647-
missingRequirement->diagnose(diag::no_witnesses,
1648-
getProtocolRequirementKind(missingRequirement),
1649-
missingRequirement,
1650-
missingRequirement->getParameters()->get(0)->getInterfaceType(),
1651-
/*AddFixIt=*/true);
1647+
missingRequirement->diagnose(
1648+
diag::no_witnesses, getProtocolRequirementKind(missingRequirement),
1649+
missingRequirement,
1650+
missingRequirement->getParameters()->get(0)->getInterfaceType());
16521651
return;
16531652
}
16541653
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,16 +3825,10 @@ static void diagnoseProtocolStubFixit(
38253825
NoStubRequirements);
38263826
auto &Diags = Ctx.Diags;
38273827

3828-
// If we are in editor mode, squash all notes into a single fixit.
3829-
if (Ctx.LangOpts.DiagnosticsEditorMode) {
3830-
if (!FixIt.empty()) {
3831-
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general).
3832-
fixItInsertAfter(FixitLocation, FixIt);
3833-
}
3834-
return;
3828+
if (!FixIt.empty()) {
3829+
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general).
3830+
fixItInsertAfter(FixitLocation, FixIt);
38353831
}
3836-
auto &SM = Ctx.SourceMgr;
3837-
auto FixitBufferId = SM.findBufferContainingLoc(FixitLocation);
38383832
for (const auto &Missing : MissingWitnesses) {
38393833
auto VD = Missing.requirement;
38403834

@@ -3843,11 +3837,6 @@ static void diagnoseProtocolStubFixit(
38433837
if (isNSObjectProtocol(VD->getDeclContext()->getSelfProtocolDecl()))
38443838
continue;
38453839

3846-
// Whether this VD has a stub printed.
3847-
bool AddFixit = !NoStubRequirements.count(VD);
3848-
bool SameFile = VD->getLoc().isValid() ?
3849-
SM.findBufferContainingLoc(VD->getLoc()) == FixitBufferId : false;
3850-
38513840
// Issue diagnostics for witness types.
38523841
if (auto MissingTypeWitness = dyn_cast<AssociatedTypeDecl>(VD)) {
38533842
std::optional<InFlightDiagnostic> diag;
@@ -3859,50 +3848,15 @@ static void diagnoseProtocolStubFixit(
38593848
diag.emplace(Diags.diagnose(MissingTypeWitness, diag::no_witnesses_type,
38603849
MissingTypeWitness));
38613850
}
3862-
if (SameFile) {
3863-
// If the protocol member decl is in the same file of the stub,
3864-
// we can directly associate the fixit with the note issued to the
3865-
// requirement.
3866-
diag->fixItInsertAfter(FixitLocation, FixIt);
3867-
} else {
3868-
diag.value().flush();
3869-
3870-
// Otherwise, we have to issue another note to carry the fixit,
3871-
// because editor may assume the fixit is in the same file with the note.
3872-
if (Ctx.LangOpts.DiagnosticsEditorMode) {
3873-
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general)
3874-
.fixItInsertAfter(FixitLocation, FixIt);
3875-
}
3876-
}
3851+
diag.value().flush();
38773852
continue;
38783853
}
38793854

38803855
// Issue diagnostics for witness values.
38813856
Type RequirementType =
38823857
getRequirementTypeForDisplay(Conf, VD);
3883-
if (AddFixit) {
3884-
if (SameFile) {
3885-
// If the protocol member decl is in the same file of the stub,
3886-
// we can directly associate the fixit with the note issued to the
3887-
// requirement.
3888-
Diags
3889-
.diagnose(VD, diag::no_witnesses, getProtocolRequirementKind(VD),
3890-
VD, RequirementType, true)
3891-
.fixItInsertAfter(FixitLocation, FixIt);
3892-
} else {
3893-
// Otherwise, we have to issue another note to carry the fixit,
3894-
// because editor may assume the fixit is in the same file with the note.
3895-
Diags.diagnose(VD, diag::no_witnesses, getProtocolRequirementKind(VD),
3896-
VD, RequirementType, false);
3897-
if (Ctx.LangOpts.DiagnosticsEditorMode) {
3898-
Diags.diagnose(ComplainLoc, diag::missing_witnesses_general)
3899-
.fixItInsertAfter(FixitLocation, FixIt);
3900-
}
3901-
}
3902-
} else {
3903-
Diags.diagnose(VD, diag::no_witnesses, getProtocolRequirementKind(VD),
3904-
VD, RequirementType, true);
3905-
}
3858+
Diags.diagnose(VD, diag::no_witnesses, getProtocolRequirementKind(VD), VD,
3859+
RequirementType);
39063860
}
39073861
}
39083862

0 commit comments

Comments
 (0)