Skip to content

Commit 54006fd

Browse files
authored
Merge pull request #36581 from bnbarham/emit-post-when-allowing-errors
[Frontend] Always output (some) additional files when allowing errors
2 parents 209878f + a17593f commit 54006fd

File tree

5 files changed

+77
-6
lines changed

5 files changed

+77
-6
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6832,8 +6832,8 @@ const ParamDecl *swift::getParameterAt(const ValueDecl *source,
68326832
Type AbstractFunctionDecl::getMethodInterfaceType() const {
68336833
assert(getDeclContext()->isTypeContext());
68346834
auto Ty = getInterfaceType();
6835-
if (Ty->hasError())
6836-
return ErrorType::get(getASTContext());
6835+
if (Ty->is<ErrorType>())
6836+
return Ty;
68376837
return Ty->castTo<AnyFunctionType>()->getResult();
68386838
}
68396839

lib/FrontendTool/FrontendTool.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,10 @@ static void emitSwiftdepsForAllPrimaryInputsIfNeeded(
640640
//
641641
// FIXME: It seems more appropriate for the driver to notice the early-exit
642642
// and react by always enqueuing the jobs it dropped in the other waves.
643-
if (Instance.getDiags().hadAnyError())
643+
//
644+
// We will output a module if allowing errors, so ignore that case.
645+
if (Instance.getDiags().hadAnyError() &&
646+
!Invocation.getFrontendOptions().AllowModuleWithCompilerErrors)
644647
return;
645648

646649
for (auto *SF : Instance.getPrimarySourceFiles()) {
@@ -989,11 +992,12 @@ static void performEndOfPipelineActions(CompilerInstance &Instance) {
989992
if (!ctx.hadError()) {
990993
emitLoadedModuleTraceForAllPrimariesIfNeeded(
991994
Instance.getMainModule(), Instance.getDependencyTracker(), opts);
992-
993-
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
994995

995996
dumpAPIIfNeeded(Instance);
996997
}
998+
if (!ctx.hadError() || opts.AllowModuleWithCompilerErrors) {
999+
emitAnyWholeModulePostTypeCheckSupplementaryOutputs(Instance);
1000+
}
9971001

9981002
// Verify reference dependencies of the current compilation job. Note this
9991003
// 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/Frontend/allow-errors.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// RUN: %empty-directory(%t)
22

33
// The module should be generated regardless of errors and diagnostic should still be output
4-
// RUN: %target-swift-frontend -verify -emit-module -o %t/errors.swiftmodule -experimental-allow-module-with-compiler-errors -D ERROR_MODULE %s
4+
// RUN: %target-swift-frontend -verify -emit-module -o %t/errors.swiftmodule -emit-reference-dependencies-path %t/errors.swiftdeps -emit-dependencies-path %t/errors.d -experimental-allow-module-with-compiler-errors -D ERROR_MODULE -primary-file %s
55
// RUN: llvm-bcanalyzer %t/errors.swiftmodule | %FileCheck -check-prefix=CHECK-BC %s
66
// CHECK-BC-NOT: UnknownCode
7+
// RUN: ls %t/errors.swiftdeps
8+
// RUN: ls %t/errors.d
9+
710
#if ERROR_MODULE
811
public struct ValidStructInvalidMember {
912
public var member: String

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)