mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Finish staging back in availability checking in synthesized functions
Remove the suppression of deprecation and potential unavailability diagnostics in synthesized functions. We still suppress some explicit unavailability diagnostics -- those in synthesized functions in synthesized functions that are lexically contained in declarations that are themselves annotated as unavailable. For these cases, the right solution <rdar://problem/20491640> is to not synthesize the bodies of these functions in the first place. rdar://problem/20024980 Swift SVN r27203
This commit is contained in:
@@ -79,11 +79,6 @@ namespace swift {
|
|||||||
/// \brief Enable experimental treatment of potentially unavailable
|
/// \brief Enable experimental treatment of potentially unavailable
|
||||||
/// symbols as optionals.
|
/// symbols as optionals.
|
||||||
bool EnableExperimentalUnavailableAsOptional = false;
|
bool EnableExperimentalUnavailableAsOptional = false;
|
||||||
|
|
||||||
/// \brief Enable availability checking in implicit functions.
|
|
||||||
/// This is a temporary flag to help testing while staging in
|
|
||||||
/// availability diagnostics on synthesized code.
|
|
||||||
bool EnableAvailabilityCheckingInImplicitFunctions = false;
|
|
||||||
|
|
||||||
/// \brief Enable support for native C function pointer types.
|
/// \brief Enable support for native C function pointer types.
|
||||||
bool EnableCFunctionPointers = false;
|
bool EnableCFunctionPointers = false;
|
||||||
|
|||||||
@@ -608,9 +608,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
|||||||
|
|
||||||
Opts.EnableExperimentalUnavailableAsOptional |=
|
Opts.EnableExperimentalUnavailableAsOptional |=
|
||||||
Args.hasArg(OPT_enable_experimental_unavailable_as_optional);
|
Args.hasArg(OPT_enable_experimental_unavailable_as_optional);
|
||||||
|
|
||||||
Opts.EnableAvailabilityCheckingInImplicitFunctions |=
|
|
||||||
Args.hasArg(OPT_enable_availability_checking_in_implicit_functions);
|
|
||||||
|
|
||||||
Opts.EnableCFunctionPointers |=
|
Opts.EnableCFunctionPointers |=
|
||||||
Args.hasArg(OPT_enable_c_function_pointers);
|
Args.hasArg(OPT_enable_c_function_pointers);
|
||||||
|
|||||||
@@ -548,18 +548,6 @@ static bool diagAvailability(TypeChecker &TC, const ValueDecl *D,
|
|||||||
if (!D)
|
if (!D)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Suppress the error if the reference is inside an
|
|
||||||
// implicit function. This avoids spurious errors for synthesized
|
|
||||||
// methods (for example, for nil literal conformances of unavailable
|
|
||||||
// imported enums) but also erroneously allows some references
|
|
||||||
// to unavailable symbols (for example, a synthesized call to
|
|
||||||
// to an unavailable default constructor of a super class).
|
|
||||||
// We need to handle these properly. rdar://problem/20024980 tracks this.
|
|
||||||
if (!TC.getLangOpts().EnableAvailabilityCheckingInImplicitFunctions &&
|
|
||||||
TC.isInsideImplicitFunction(R, DC)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (diagnoseExplicitUnavailability(TC, D, R, DC))
|
if (diagnoseExplicitUnavailability(TC, D, R, DC))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
@@ -2049,22 +2049,6 @@ void TypeChecker::diagnoseDeprecated(SourceRange ReferenceRange,
|
|||||||
const DeclContext *ReferenceDC,
|
const DeclContext *ReferenceDC,
|
||||||
const AvailabilityAttr *Attr,
|
const AvailabilityAttr *Attr,
|
||||||
DeclName Name) {
|
DeclName Name) {
|
||||||
|
|
||||||
// Suppress the warning if the reference is inside an
|
|
||||||
// implicit function. This avoids spurious warnings for synthesized
|
|
||||||
// methods (for example, for nil literal conformances of deprecated
|
|
||||||
// imported enums) but also erroneously allows some references
|
|
||||||
// to deprecated symbols (for example, a synthesized call to
|
|
||||||
// to a deprecated default constructor of a super class).
|
|
||||||
// We should emit special-case diagnostics for those cases
|
|
||||||
// where the compiler will synthesize a reference to
|
|
||||||
// a deprecated API element. rdar://problem/20024980 tracks these
|
|
||||||
// special-case diagnostics.
|
|
||||||
if (!getLangOpts().EnableAvailabilityCheckingInImplicitFunctions &&
|
|
||||||
isInsideImplicitFunction(ReferenceRange, ReferenceDC)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We match the behavior of clang to not report deprecation warnigs
|
// We match the behavior of clang to not report deprecation warnigs
|
||||||
// inside declarations that are themselves deprecated on all deployment
|
// inside declarations that are themselves deprecated on all deployment
|
||||||
// targets.
|
// targets.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// RUN: %swift -parse -verify -target x86_64-apple-macosx10.10 -enable-experimental-availability-checking -enable-availability-checking-in-implicit-functions %clang-importer-sdk -I %S/Inputs/custom-modules %s
|
// RUN: %swift -parse -verify -target x86_64-apple-macosx10.10 -enable-experimental-availability-checking %clang-importer-sdk -I %S/Inputs/custom-modules %s
|
||||||
// RUN: not %swift -parse -target x86_64-apple-macosx10.10 -enable-experimental-availability-checking -enable-availability-checking-in-implicit-functions %clang-importer-sdk -I %S/Inputs/custom-modules %s 2>&1 | FileCheck %s '--implicit-check-not=<unknown>:0'
|
// RUN: not %swift -parse -target x86_64-apple-macosx10.10 -enable-experimental-availability-checking %clang-importer-sdk -I %S/Inputs/custom-modules %s 2>&1 | FileCheck %s '--implicit-check-not=<unknown>:0'
|
||||||
|
|
||||||
// REQUIRES: OS=macosx
|
// REQUIRES: OS=macosx
|
||||||
|
|
||||||
@@ -20,6 +20,14 @@ func useClassThatTriggersImportOfDeprecatedEnum() {
|
|||||||
let _ = NSClassWithDeprecatedOptionsInMethodSignature.sharedInstance()
|
let _ = NSClassWithDeprecatedOptionsInMethodSignature.sharedInstance()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func useClassThatTriggersImportOExplicitlyUnavailableOptions() {
|
||||||
|
let _ = NSClassWithPotentiallyUnavailableOptionsInMethodSignature.sharedInstance()
|
||||||
|
}
|
||||||
|
|
||||||
|
func useClassThatTriggersImportOfPotentiallyUnavailableOptions() {
|
||||||
|
let _ = NSClassWithExplicitlyUnavailableOptionsInMethodSignature.sharedInstance()
|
||||||
|
}
|
||||||
|
|
||||||
func directUseShouldStillTriggerDeprecationWarning() {
|
func directUseShouldStillTriggerDeprecationWarning() {
|
||||||
let _ = NSDeprecatedOptions.First // expected-warning {{'NSDeprecatedOptions' was deprecated in OS X 10.10: Use a different API}}
|
let _ = NSDeprecatedOptions.First // expected-warning {{'NSDeprecatedOptions' was deprecated in OS X 10.10: Use a different API}}
|
||||||
let _ = NSDeprecatedEnum.First // expected-warning {{'NSDeprecatedEnum' was deprecated in OS X 10.10: Use a different API}}
|
let _ = NSDeprecatedEnum.First // expected-warning {{'NSDeprecatedEnum' was deprecated in OS X 10.10: Use a different API}}
|
||||||
|
|||||||
@@ -34,9 +34,9 @@
|
|||||||
//
|
//
|
||||||
// REQUIRES: OS=macosx
|
// REQUIRES: OS=macosx
|
||||||
|
|
||||||
// FOUNDATION-LABEL: {{^}}/// Aaa. NSUnavailableOptions. Bbb.
|
// FOUNDATION-LABEL: {{^}}/// Aaa. NSPotentiallyUnavailableOptions. Bbb.
|
||||||
// FOUNDATION-NEXT: {{^}}@availability(OSX, introduced=10.10){{$}}
|
// FOUNDATION-NEXT: {{^}}@availability(OSX, introduced=10.10){{$}}
|
||||||
// FOUNDATION-NEXT: {{^}}struct NSUnavailableOptions : RawOptionSetType {{{$}}
|
// FOUNDATION-NEXT: {{^}}struct NSPotentiallyUnavailableOptions : RawOptionSetType {{{$}}
|
||||||
|
|
||||||
// FOUNDATION-LABEL: {{^}}/// Aaa. NSOptionsWithUnavailableElement. Bbb.
|
// FOUNDATION-LABEL: {{^}}/// Aaa. NSOptionsWithUnavailableElement. Bbb.
|
||||||
// FOUNDATION-NEXT: {{^}}struct NSOptionsWithUnavailableElement : RawOptionSetType {{{$}}
|
// FOUNDATION-NEXT: {{^}}struct NSOptionsWithUnavailableElement : RawOptionSetType {{{$}}
|
||||||
|
|||||||
@@ -440,11 +440,11 @@ typedef NS_OPTIONS(NSUInteger, NSABitmapFormat5) {
|
|||||||
NSAB32d,
|
NSAB32d,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Aaa. NSUnavailableOptions. Bbb.
|
/// Aaa. NSPotentiallyUnavailableOptions. Bbb.
|
||||||
typedef NS_OPTIONS(NSUInteger, NSUnavailableOptions) {
|
typedef NS_OPTIONS(NSUInteger, NSPotentiallyUnavailableOptions) {
|
||||||
NSUnavailableOptionsFirst = (1 << 0),
|
NSPotentiallyUnavailableOptionsFirst = (1 << 0),
|
||||||
NSUnavailableOptionsSecond = (1 << 1),
|
NSPotentiallyUnavailableOptionsSecond = (1 << 1),
|
||||||
NSUnavailableOptionsThird = (1 << 2),
|
NSPotentiallyUnavailableOptionsThird = (1 << 2),
|
||||||
} __attribute__((availability(macosx, introduced=10.10)));
|
} __attribute__((availability(macosx, introduced=10.10)));
|
||||||
|
|
||||||
/// Aaa. NSOptionsWithUnavailableElement. Bbb.
|
/// Aaa. NSOptionsWithUnavailableElement. Bbb.
|
||||||
@@ -506,6 +506,11 @@ typedef NS_OPTIONS(NSUInteger, NSExplicitlyUnavailableOnOSXOptions) {
|
|||||||
- (void)someMethodWithUnavailableOptionsOnOSX:(NSExplicitlyUnavailableOnOSXOptions)options __attribute__((availability(macosx, unavailable, message="Use a different API")));
|
- (void)someMethodWithUnavailableOptionsOnOSX:(NSExplicitlyUnavailableOnOSXOptions)options __attribute__((availability(macosx, unavailable, message="Use a different API")));
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface NSClassWithPotentiallyUnavailableOptionsInMethodSignature : NSObject
|
||||||
|
+ (NSClassWithPotentiallyUnavailableOptionsInMethodSignature *) sharedInstance;
|
||||||
|
- (void)someMethodWithPotentiallyUnavailableOptions:(NSPotentiallyUnavailableOptions)options __attribute__((availability(macosx, introduced=10.11)));
|
||||||
|
@end
|
||||||
|
|
||||||
@protocol NSWobbling
|
@protocol NSWobbling
|
||||||
-(void)wobble;
|
-(void)wobble;
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class ClassAdoptingUnavailableProtocol : NSProtocolAvailableOn10_10 { // expecte
|
|||||||
|
|
||||||
// Enums from Objective-C
|
// Enums from Objective-C
|
||||||
|
|
||||||
let _: NSUnavailableOptions = .First // expected-error {{'NSUnavailableOptions' is only available on OS X 10.10 or newer}}
|
let _: NSPotentiallyUnavailableOptions = .First // expected-error {{'NSPotentiallyUnavailableOptions' is only available on OS X 10.10 or newer}}
|
||||||
// expected-note@-1 {{guard with version check}}
|
// expected-note@-1 {{guard with version check}}
|
||||||
|
|
||||||
let _: NSOptionsWithUnavailableElement = .Third // expected-error {{'Third' is only available on OS X 10.10 or newer}}
|
let _: NSOptionsWithUnavailableElement = .Third // expected-error {{'Third' is only available on OS X 10.10 or newer}}
|
||||||
|
|||||||
Reference in New Issue
Block a user