Skip to content

Sema: Still diagnose '@objc' even if Foundation was imported #34773

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
Nov 17, 2020
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
24 changes: 12 additions & 12 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1051,26 +1051,26 @@ static void diagnoseObjCAttrWithoutFoundation(ObjCAttr *attr, Decl *decl) {
return;

auto &ctx = SF->getASTContext();
if (ctx.LangOpts.EnableObjCInterop) {
// Don't diagnose in a SIL file.
if (SF->Kind == SourceFileKind::SIL)
return;

// Don't diagnose for -disable-objc-attr-requires-foundation-module.
if (!ctx.LangOpts.EnableObjCAttrRequiresFoundation)
return;
if (!ctx.LangOpts.EnableObjCInterop) {
ctx.Diags.diagnose(attr->getLocation(), diag::objc_interop_disabled)
.fixItRemove(attr->getRangeWithAt());
return;
}

// Don't diagnose in a SIL file.
if (SF->Kind == SourceFileKind::SIL)
return;

// Don't diagnose for -disable-objc-attr-requires-foundation-module.
if (!ctx.LangOpts.EnableObjCAttrRequiresFoundation)
return;

// If we have the Foundation module, @objc is okay.
auto *foundation = ctx.getLoadedModule(ctx.Id_Foundation);
if (foundation && ctx.getImportCache().isImportedBy(foundation, SF))
return;

if (!ctx.LangOpts.EnableObjCInterop) {
ctx.Diags.diagnose(attr->getLocation(), diag::objc_interop_disabled)
.fixItRemove(attr->getRangeWithAt());
}

ctx.Diags.diagnose(attr->getLocation(),
diag::attr_used_without_required_module, attr,
ctx.Id_Foundation)
Expand Down
2 changes: 1 addition & 1 deletion test/SourceKit/Sema/objc_attr_without_import.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %FileCheck -input-file=%t.response %s
// This tests that we are not crashing in SILGen.

// CHECK: @objc attribute used without importing module
// CHECK: {{Objective-C interoperability is disabled|@objc attribute used without importing module}}
@objc protocol Communicate {
var name: String { get }
}
Expand Down
10 changes: 10 additions & 0 deletions validation-test/compiler_crashers_2_fixed/sr13713.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-typecheck-verify-swift -disable-objc-interop -module-name Foundation

// Make sure we diagnose this even if the current module is named 'Foundation':
@objc protocol Horse { // expected-error {{Objective-C interoperability is disabled}}
func ride()
}

func rideHorse(_ horse: Horse) {
horse.ride()
}