Skip to content

Commit 4837853

Browse files
committed
Improve Over-Availability Diagnostic for Implicit Decls
We used to attach this diagnostic to the implicit decl. Now, attach it to the enclosing decl and offer an extra note that states the availability of the implicit declaration that is at conflict with the availability of the enclosing scope. rdar://74513654
1 parent 48849dc commit 4837853

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5578,6 +5578,10 @@ ERROR(availability_decl_more_than_enclosing, none,
55785578
"%0 cannot be more available than enclosing scope",
55795579
(DescriptiveDeclKind))
55805580

5581+
NOTE(availability_implicit_decl_here, none,
5582+
"%0 implicitly declared here with availability of %1 %2 or newer",
5583+
(DescriptiveDeclKind, StringRef, llvm::VersionTuple))
5584+
55815585
NOTE(availability_decl_more_than_enclosing_enclosing_here, none,
55825586
"enclosing scope requires availability of %0 %1 or newer",
55835587
(StringRef, llvm::VersionTuple))

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,12 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
17131713
diagnose(D->isImplicit() ? EnclosingDecl->getLoc() : attr->getLocation(),
17141714
diag::availability_decl_more_than_enclosing,
17151715
D->getDescriptiveKind());
1716+
if (D->isImplicit())
1717+
diagnose(EnclosingDecl->getLoc(),
1718+
diag::availability_implicit_decl_here,
1719+
D->getDescriptiveKind(),
1720+
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
1721+
AttrRange.getOSVersion().getLowerEndpoint());
17161722
diagnose(EnclosingDecl->getLoc(),
17171723
diag::availability_decl_more_than_enclosing_enclosing_here,
17181724
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@import Foundation;
2+
3+
__attribute__((availability(macosx,introduced=10.0)))
4+
__attribute__((availability(ios,introduced=2.0)))
5+
__attribute__((availability(tvos,introduced=1.0)))
6+
__attribute__((availability(watchos,introduced=2.0)))
7+
__attribute__((availability(maccatalyst,introduced=13.1)))
8+
@interface NSBaseClass : NSObject
9+
- (instancetype) init
10+
__attribute__((objc_designated_initializer))
11+
__attribute__((availability(macosx,introduced=10.0)))
12+
__attribute__((availability(ios,introduced=2.0)))
13+
__attribute__((availability(tvos,introduced=1.0)))
14+
__attribute__((availability(watchos,introduced=2.0)))
15+
__attribute__((availability(maccatalyst,introduced=13.1)));
16+
@end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module AttrObjc_FooClangModule { header "attr_objc_foo_clang_module.h" }
22
module Testable_ClangModule { header "testable_clang.h" }
33
module ObjcAsync { header "objc_async.h" }
4+
module Available_NSObject { header "available_nsobject.h" }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -I %t -I %S/Inputs/custom-modules -parse-stdlib -parse-as-library -typecheck -verify -target x86_64-apple-ios15.4-macabi %s
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: maccatalyst_support
5+
6+
import Available_NSObject
7+
8+
@available(iOS 15.0, *)
9+
open class OverAvailableClass: NSBaseClass {}
10+
// expected-error@-1 {{initializer cannot be more available than enclosing scope}}
11+
// expected-note@-2 {{initializer implicitly declared here with availability of Mac Catalyst 13.1 or newer}}
12+
// expected-note@-3 {{enclosing scope requires availability of Mac Catalyst 15.0 or newer}}
13+

0 commit comments

Comments
 (0)