Skip to content

[PrintAsObjC] Do not output invalid decls when allowing errors #38923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/PrintAsObjC/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ auto DeclAndTypePrinter::getImpl() -> Implementation {
}

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

Expand Down
16 changes: 12 additions & 4 deletions test/PrintAsObjC/error.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %FileCheck %s < %t/error.h
// RUN: %FileCheck --input-file %t/error.h %s
// RUN: %check-in-clang %t/error.h

// REQUIRES: objc_interop

import Foundation

// TODO: Ideally we'd output invalid decls regardless (so that they could eg. be used in code
// completion), but we avoid doing so for now to prevent crashes. Revisit later to handle a possibly
// invalid AST while printing the ObjectiveC header - see SR-15088.

@objc class ErrorClass: NSObject {
// CHECK: @interface ErrorClass
@objc let member: Int
// CHECK: @property {{.*}} NSInteger member;

@objc let invalidMember: undefined
// TODO: Not output on invalid type
// TODO: Missing

@objc func method() {}
// CHECK: - (void)method;
Expand All @@ -33,10 +38,10 @@ import Foundation
}

@objc func invalidRet() -> undefined {}
// CHECK: - (/* error */id)invalidRet
// TODO: Missing

@objc func invalidParams(a: undefined) {}
// TODO: Not output with invalid parameters
// TODO: Missing

@objc(invalid::)
func invalidRenamedMethod() {}
Expand All @@ -55,3 +60,6 @@ import Foundation

@objc class InvalidParent: undefined {}
// CHECK: @interface InvalidParent

// Used to crash during sorting due to assumptions regarding the Decl kind
@objc class ErrorClass: NSObject {}