Skip to content

Commit 995dec5

Browse files
committed
[Sema] Error if ObjC interop is needed when disabled
1 parent a27c5c2 commit 995dec5

File tree

93 files changed

+338
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+338
-270
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,6 +3352,9 @@ ERROR(sil_metatype_multiple_reprs,none,
33523352
// @objc and @nonobjc
33533353
//------------------------------------------------------------------------------
33543354

3355+
ERROR(objc_interop_disabled,none,
3356+
"Objective-C interoperability is disabled", ())
3357+
33553358
ERROR(attr_used_without_required_module, none,
33563359
"%0 attribute used without importing module %1",
33573360
(DeclAttribute, Identifier))

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,9 +2324,12 @@ bool swift::fixDeclarationObjCName(InFlightDiagnostic &diag, ValueDecl *decl,
23242324
void ASTContext::diagnoseAttrsRequiringFoundation(SourceFile &SF) {
23252325
bool ImportsFoundationModule = false;
23262326

2327-
if (SF.Kind == SourceFileKind::SIL ||
2328-
!LangOpts.EnableObjCAttrRequiresFoundation)
2329-
return;
2327+
if (LangOpts.EnableObjCInterop) {
2328+
if (!LangOpts.EnableObjCAttrRequiresFoundation)
2329+
return;
2330+
if (SF.Kind == SourceFileKind::SIL)
2331+
return;
2332+
}
23302333

23312334
SF.forAllVisibleModules([&](ModuleDecl::ImportedModule import) {
23322335
if (import.second->getName() == Id_Foundation)
@@ -2337,6 +2340,9 @@ void ASTContext::diagnoseAttrsRequiringFoundation(SourceFile &SF) {
23372340
return;
23382341

23392342
for (auto Attr : SF.AttrsRequiringFoundation) {
2343+
if (!LangOpts.EnableObjCInterop)
2344+
Diags.diagnose(Attr->getLocation(), diag::objc_interop_disabled)
2345+
.fixItRemove(Attr->getRangeWithAt());
23402346
Diags.diagnose(Attr->getLocation(),
23412347
diag::attr_used_without_required_module,
23422348
Attr, Id_Foundation)

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6437,10 +6437,13 @@ static Optional<ObjCReason> shouldMarkClassAsObjC(TypeChecker &TC,
64376437

64386438
// Only allow ObjC-rooted classes to be @objc.
64396439
// (Leave a hole for test cases.)
6440-
if (kind == ObjCClassKind::ObjCWithSwiftRoot &&
6441-
TC.getLangOpts().EnableObjCAttrRequiresFoundation) {
6442-
TC.diagnose(attr->getLocation(), diag::invalid_objc_swift_rooted_class)
6443-
.fixItRemove(attr->getRangeWithAt());
6440+
if (kind == ObjCClassKind::ObjCWithSwiftRoot) {
6441+
if (TC.getLangOpts().EnableObjCAttrRequiresFoundation)
6442+
TC.diagnose(attr->getLocation(), diag::invalid_objc_swift_rooted_class)
6443+
.fixItRemove(attr->getRangeWithAt());
6444+
if (!TC.getLangOpts().EnableObjCInterop)
6445+
TC.diagnose(attr->getLocation(), diag::objc_interop_disabled)
6446+
.fixItRemove(attr->getRangeWithAt());
64446447
}
64456448

64466449
return ObjCReason::ExplicitlyObjC;

test/Compatibility/attr_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 3
1+
// RUN: %target-swift-frontend -enable-objc-interop -disable-objc-attr-requires-foundation-module -typecheck -verify %s -swift-version 3
22

33
class Load1 {
44
class func load() { }

test/Compatibility/override.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -parse-as-library -swift-version 3
1+
// RUN: %target-typecheck-verify-swift -parse-as-library -swift-version 3 -enable-objc-interop
22

33
class A {
44
@objc func objcVirtualFunction() { } // expected-note{{overridden declaration is here}}

test/Constraints/casts.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-objc-interop
22

33
class B {
44
init() {}

test/Constraints/generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-objc-interop
22

33
infix operator +++
44

test/Constraints/members_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-objc-interop
22

33
import Swift
44

test/Generics/existential_restrictions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift
1+
// RUN: %target-typecheck-verify-swift -enable-objc-interop
22

33
protocol P { }
44
@objc protocol OP { }

test/IDE/comment_to_xml.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//===--- Check that we convert comments to XML correctly.
22

3-
// RUN: %target-swift-frontend -typecheck -verify -disable-objc-attr-requires-foundation-module %S/../Inputs/comment_to_something_conversion.swift
4-
// RUN: %target-swift-ide-test -module-name comment_to_xml -print-comments -source-filename %S/../Inputs/comment_to_something_conversion.swift -comments-xml-schema %S/../../bindings/xml/comment-xml-schema.rng > %t.txt
3+
// RUN: %target-swift-frontend -typecheck -verify -disable-objc-attr-requires-foundation-module -enable-objc-interop %S/../Inputs/comment_to_something_conversion.swift
4+
// RUN: %target-swift-ide-test -enable-objc-interop -module-name comment_to_xml -print-comments -source-filename %S/../Inputs/comment_to_something_conversion.swift -comments-xml-schema %S/../../bindings/xml/comment-xml-schema.rng > %t.txt
55
// RUN: %FileCheck %S/../Inputs/comment_to_something_conversion.swift < %t.txt
66
// RUN: %FileCheck %s -check-prefix=WRONG < %t.txt
77

test/IDE/complete_from_clang_framework_typechecker.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -F %S/Inputs/mock-sdk
2-
3-
// XFAIL: linux, freebsd
1+
// RUN: %target-typecheck-verify-swift -enable-objc-interop -F %S/Inputs/mock-sdk
42

53
import Foo
64
// Don't import 'FooHelper'.

test/IDE/complete_members_optional.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: sed -n -e '1,/NO_ERRORS_UP_TO_HERE$/ p' %s > %t_no_errors.swift
2-
// RUN: %target-swift-frontend -typecheck -verify -disable-objc-attr-requires-foundation-module %t_no_errors.swift
2+
// RUN: %target-swift-frontend -typecheck -verify -disable-objc-attr-requires-foundation-module -enable-objc-interop %t_no_errors.swift
33

4-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OPTIONAL_MEMBERS_1 | %FileCheck %s -check-prefix=OPTIONAL_MEMBERS_1
5-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OPTIONAL_MEMBERS_2 | %FileCheck %s -check-prefix=OPTIONAL_MEMBERS_2
4+
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=OPTIONAL_MEMBERS_1 | %FileCheck %s -check-prefix=OPTIONAL_MEMBERS_1
5+
// RUN: %target-swift-ide-test -enable-objc-interop -code-completion -source-filename %s -code-completion-token=OPTIONAL_MEMBERS_2 | %FileCheck %s -check-prefix=OPTIONAL_MEMBERS_2
66

77
@objc
88
protocol HasOptionalMembers1 {

0 commit comments

Comments
 (0)