Skip to content

Commit 6db9e3e

Browse files
committed
[PrintAsObjC] Do not output invalid decls when allowing errors
We still want the ObjectiveC header when allowing errors, but make sure to skip printing out any invalid declarations that may be caused because of those errors. In particular, duplicate declarations were causing a crash when sorting declarations where various assumptions would end up casting a non-ExtensionDecl to an ExtensionDecl. Resolves rdar://78023656
1 parent a3e72f5 commit 6db9e3e

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,7 @@ auto DeclAndTypePrinter::getImpl() -> Implementation {
20172017
}
20182018

20192019
bool DeclAndTypePrinter::shouldInclude(const ValueDecl *VD) {
2020-
return isVisibleToObjC(VD, minRequiredAccess) &&
2020+
return !VD->isInvalid() && isVisibleToObjC(VD, minRequiredAccess) &&
20212021
!VD->getAttrs().hasAttribute<ImplementationOnlyAttr>();
20222022
}
20232023

test/PrintAsObjC/error.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
// RUN: %empty-directory(%t)
22
// 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
3-
// RUN: %FileCheck %s < %t/error.h
3+
// RUN: %FileCheck --input-file %t/error.h %s
44
// RUN: %check-in-clang %t/error.h
55

66
// REQUIRES: objc_interop
77

88
import Foundation
99

10+
// TODO: Ideally we'd output invalid decls regardless (so that they could eg. be used in code
11+
// completion), but we avoid doing so for now to prevent crashes. Revisit later to handle a possibly
12+
// invalid AST while printing the ObjectiveC header.
13+
1014
@objc class ErrorClass: NSObject {
1115
// CHECK: @interface ErrorClass
1216
@objc let member: Int
1317
// CHECK: @property {{.*}} NSInteger member;
18+
1419
@objc let invalidMember: undefined
15-
// TODO: Not output on invalid type
20+
// TODO: Missing
1621

1722
@objc func method() {}
1823
// CHECK: - (void)method;
@@ -33,10 +38,10 @@ import Foundation
3338
}
3439

3540
@objc func invalidRet() -> undefined {}
36-
// CHECK: - (/* error */id)invalidRet
41+
// TODO: Missing
3742

3843
@objc func invalidParams(a: undefined) {}
39-
// TODO: Not output with invalid parameters
44+
// TODO: Missing
4045

4146
@objc(invalid::)
4247
func invalidRenamedMethod() {}
@@ -55,3 +60,6 @@ import Foundation
5560

5661
@objc class InvalidParent: undefined {}
5762
// CHECK: @interface InvalidParent
63+
64+
// Used to crash during sorting due to assumptions regarding the Decl kind
65+
@objc class ErrorClass: NSObject {}

0 commit comments

Comments
 (0)