Skip to content

Commit 79e2060

Browse files
committed
Exempt Swift Interface Files From Whole-Module ObjC Errors
We don't expect swiftinterface files to have anything meaningful to report from these checks anyhow - they will have been run at module generation time anyways. In fact, the linked radar demonstrates how this kind of checking can be detrimental to the usability of the compiler. The test committed here declares the CoreFeatures framework, an Objective-c (root) class and a set of Objective-C protocols. Now for the fun part: The Objective-C class is made to conform to the Objective-C protocols in a Swift extension. This extension is then printed into the generated CoreFeatures-Swift header and made available to clients of the module. Now, because we have an Objective-C protocol and a base class that is imported from Objective-C, we mirror-in the members of RootProtocol. The sum total of the monster we have built is that we now have a Swift class that implements some requirements, and an Objective-C protocol that has requirements mirrored into that same class. The result is a raft of spurious selector conflict diagnostics that the user cannot work around unless they own both the class and the protocol. Exempt swiftinterface files from this checking. rdar://69550935
1 parent 58a88c1 commit 79e2060

20 files changed

+546
-3
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,7 @@ bool swift::diagnoseObjCUnsatisfiedOptReqConflicts(SourceFile &sf) {
23872387
break;
23882388
}
23892389
}
2390+
assert(req != bestConflict && "requirement conflicts with itself?");
23902391

23912392
// Diagnose the conflict.
23922393
auto reqDiagInfo = getObjCMethodDiagInfo(unsatisfied.second);

lib/Sema/TypeChecker.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,19 @@ void swift::performWholeModuleTypeChecking(SourceFile &SF) {
344344
auto &Ctx = SF.getASTContext();
345345
FrontendStatsTracer tracer(Ctx.Stats,
346346
"perform-whole-module-type-checking");
347-
diagnoseObjCMethodConflicts(SF);
348-
diagnoseObjCUnsatisfiedOptReqConflicts(SF);
349-
diagnoseUnintendedObjCMethodOverrides(SF);
347+
switch (SF.Kind) {
348+
case SourceFileKind::Library:
349+
case SourceFileKind::Main:
350+
diagnoseObjCMethodConflicts(SF);
351+
diagnoseObjCUnsatisfiedOptReqConflicts(SF);
352+
diagnoseUnintendedObjCMethodOverrides(SF);
353+
return;
354+
case SourceFileKind::SIL:
355+
case SourceFileKind::Interface:
356+
// SIL modules and .swiftinterface files don't benefit from whole-module
357+
// ObjC checking - skip it.
358+
return;
359+
}
350360
}
351361

352362
bool swift::isAdditiveArithmeticConformanceDerivationEnabled(SourceFile &SF) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/CoreFeatures
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Headers
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Versions/Current/Modules

0 commit comments

Comments
 (0)