Skip to content

Commit ab5a421

Browse files
committed
[Frontend] Always emit generated ObjectiveC header when allowing errors
Resolves rdar://75754282
1 parent fe10f31 commit ab5a421

File tree

4 files changed

+69
-4
lines changed

4 files changed

+69
-4
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6808,8 +6808,8 @@ const ParamDecl *swift::getParameterAt(const ValueDecl *source,
68086808
Type AbstractFunctionDecl::getMethodInterfaceType() const {
68096809
assert(getDeclContext()->isTypeContext());
68106810
auto Ty = getInterfaceType();
6811-
if (Ty->hasError())
6812-
return ErrorType::get(getASTContext());
6811+
if (Ty->is<ErrorType>())
6812+
return Ty;
68136813
return Ty->castTo<AnyFunctionType>()->getResult();
68146814
}
68156815

lib/FrontendTool/FrontendTool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,12 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
989989
if (!ctx.hadError()) {
990990
emitLoadedModuleTraceForAllPrimariesIfNeeded(
991991
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
992-
993-
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
994992

995993
dumpAPIIfNeeded(Instance);
996994
}
995+
if (!ctx.hadError() || opts.AllowModuleWithCompilerErrors) {
996+
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
997+
}
997998

998999
// Verify reference dependencies of the current compilation job. Note this
9991000
// must be run *before* verifying diagnostics so that the former can be tested

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,10 @@ class DeclAndTypePrinter::Implementation
15971597
os << " */";
15981598
}
15991599

1600+
void visitErrorType(ErrorType *Ty, Optional<OptionalTypeKind> optionalKind) {
1601+
os << "/* error */id";
1602+
}
1603+
16001604
bool isClangPointerType(const clang::TypeDecl *clangTypeDecl) const {
16011605
ASTContext &ctx = getASTContext();
16021606
auto &clangASTContext = ctx.getClangModuleLoader()->getClangASTContext();

test/PrintAsObjC/error.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// RUN: %empty-directory(%t)
2+
// RdsagUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -typecheck -emit-objc-header-path %t/error.h
3+
// RUadsgN: %FileCheck %s < %t/error.h
4+
5+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module-path %t/error.swiftmodule -emit-objc-header-path %t/error.h -experimental-allow-module-with-compiler-errors %s
6+
// RUN: %FileCheck %s < %t/error.h
7+
// RUN: %check-in-clang %t/error.h
8+
9+
// REQUIRES: objc_interop
10+
11+
import Foundation
12+
13+
@objc class ErrorClass: NSObject {
14+
// CHECK: @interface ErrorClass
15+
@objc let member: Int
16+
// CHECK: @property {{.*}} NSInteger member;
17+
@objc let invalidMember: undefined
18+
// TODO: Not output on invalid type
19+
20+
@objc func method() {}
21+
// CHECK: - (void)method;
22+
23+
@objc func methodParams(a: Int, b: Int) {}
24+
// CHECK: - (void)methodParamsWithA:(NSInteger)a b:(NSInteger)b;
25+
26+
@objc class func classMethod() {}
27+
// CHECK: + (void)classMethod;
28+
29+
@objc(objcMethod)
30+
func renamedMethod() {}
31+
// CHECK: - (void)objcMethod;
32+
33+
@objc func invalidBody() {
34+
// CHECK: - (void)invalidBody;
35+
undefined
36+
}
37+
38+
@objc func invalidRet() -> undefined {}
39+
// CHECK: - (/* error */id)invalidRet
40+
41+
@objc func invalidParams(a: undefined) {}
42+
// TODO: Not output with invalid parameters
43+
44+
@objc(invalid::)
45+
func invalidRenamedMethod() {}
46+
// CHECK: - (void)invalidRenamedMethod;
47+
48+
@objc @undefined func invalidAttribute() {}
49+
// CHECK: - (void)invalidAttribute;
50+
51+
@objc undefined func invalidModifier() {}
52+
// TODO: Not output with invalid modifier
53+
54+
@objc @available
55+
func invalidAvailability() {}
56+
// CHECK: - (void)invalidAvailability;
57+
}
58+
59+
@objc class InvalidParent: undefined {}
60+
// CHECK: @interface InvalidParent

0 commit comments

Comments
 (0)