@@ -816,6 +816,7 @@ static void emitIndexData(const CompilerInstance &Instance) {
816816// / anything past type-checking.
817817static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs (
818818 CompilerInstance &Instance) {
819+ const auto &Context = Instance.getASTContext ();
819820 const auto &Invocation = Instance.getInvocation ();
820821 const FrontendOptions &opts = Invocation.getFrontendOptions ();
821822
@@ -834,7 +835,8 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
834835 // failure does not mean skipping the rest.
835836 bool hadAnyError = false ;
836837
837- if (opts.InputsAndOutputs .hasObjCHeaderOutputPath ()) {
838+ if ((!Context.hadError () || opts.AllowModuleWithCompilerErrors ) &&
839+ opts.InputsAndOutputs .hasObjCHeaderOutputPath ()) {
838840 std::string BridgingHeaderPathForPrint;
839841 if (!opts.ImplicitObjCHeaderPath .empty ()) {
840842 if (opts.BridgingHeaderDirForPrint .hasValue ()) {
@@ -854,6 +856,11 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
854856 Invocation.isModuleExternallyConsumed (Instance.getMainModule ()));
855857 }
856858
859+ // Only want the header if there's been any errors, ie. there's not much
860+ // point outputting a swiftinterface for an invalid module
861+ if (Context.hadError ())
862+ return hadAnyError;
863+
857864 if (opts.InputsAndOutputs .hasModuleInterfaceOutputPath ()) {
858865 hadAnyError |= printModuleInterfaceIfNeeded (
859866 Invocation.getModuleInterfaceOutputPathForWholeModule (),
@@ -996,9 +1003,10 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
9961003
9971004 dumpAPIIfNeeded (Instance);
9981005 }
999- if (!ctx.hadError () || opts.AllowModuleWithCompilerErrors ) {
1000- emitAnyWholeModulePostTypeCheckSupplementaryOutputs (Instance);
1001- }
1006+
1007+ // Contains the hadError checks internally, we still want to output the
1008+ // Objective-C header when there's errors and currently allowing them
1009+ emitAnyWholeModulePostTypeCheckSupplementaryOutputs (Instance);
10021010
10031011 // Verify reference dependencies of the current compilation job. Note this
10041012 // must be run *before* verifying diagnostics so that the former can be tested
0 commit comments