1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
// RUN: %swift -typecheck -verify -target %target-cpu-apple-macosx51 %clang-importer-sdk -I %S/Inputs/custom-modules %s %S/Inputs/availability_implicit_macosx_other.swift
// RUN: not %swift -typecheck -target %target-cpu-apple-macosx51 %clang-importer-sdk -I %S/Inputs/custom-modules %s %S/Inputs/availability_implicit_macosx_other.swift 2>&1 | %FileCheck %s '--implicit-check-not=<unknown>:0'
// REQUIRES: OS=macosx
// This is a temporary test for checking of availability diagnostics (explicit unavailability,
// deprecation, and potential unavailability) in synthesized code. After this checking
// is fully staged in, the tests in this file will be moved.
//
import Foundation
func useClassThatTriggersImportOfDeprecatedEnum() {
// Check to make sure that the bodies of enum methods that are synthesized
// when importing deprecated enums do not themselves trigger deprecation
// warnings in the synthesized code.
_ = NSClassWithDeprecatedOptionsInMethodSignature.sharedInstance()
}
func useClassThatTriggersImportOExplicitlyUnavailableOptions() {
_ = NSClassWithPotentiallyUnavailableOptionsInMethodSignature.sharedInstance()
}
func useClassThatTriggersImportOfPotentiallyUnavailableOptions() {
_ = NSClassWithExplicitlyUnavailableOptionsInMethodSignature.sharedInstance()
}
func directUseShouldStillTriggerDeprecationWarning() {
_ = NSDeprecatedOptions.first // expected-warning {{'NSDeprecatedOptions' was deprecated in macOS 51: Use a different API}}
_ = NSDeprecatedEnum.first // expected-warning {{'NSDeprecatedEnum' was deprecated in macOS 51: Use a different API}}
}
func useInSignature(_ options: NSDeprecatedOptions) { // expected-warning {{'NSDeprecatedOptions' was deprecated in macOS 51: Use a different API}}
}
class SuperClassWithDeprecatedInitializer {
@available(OSX, introduced: 10.9, deprecated: 51)
init() { }
}
class SubClassWithSynthesizedDesignedInitializerOverride : SuperClassWithDeprecatedInitializer {
// The synthesized designated initializer override calls super.init(), which is
// deprecated, so the synthesized initializer is marked as deprecated as well.
// This does not generate a warning here (perhaps it should?) but any call
// to Sub's initializer will cause a deprecation warning.
}
func callImplicitInitializerOnSubClassWithSynthesizedDesignedInitializerOverride() {
_ = SubClassWithSynthesizedDesignedInitializerOverride() // expected-warning {{'init()' was deprecated in macOS 51}}
}
@available(OSX, introduced: 10.9, deprecated: 51)
class NSDeprecatedSuperClass {
var i : Int = 7 // Causes initializer to be synthesized
}
class NotDeprecatedSubClassOfDeprecatedSuperClass : NSDeprecatedSuperClass { // expected-warning {{'NSDeprecatedSuperClass' was deprecated in macOS 51}}
}
func callImplicitInitializerOnNotDeprecatedSubClassOfDeprecatedSuperClass() {
// We do not expect a warning here because the synthesized initializer
// in NotDeprecatedSubClassOfDeprecatedSuperClass is not itself marked
// deprecated.
_ = NotDeprecatedSubClassOfDeprecatedSuperClass()
}
@available(OSX, introduced: 10.9, deprecated: 51)
class NSDeprecatedSubClassOfDeprecatedSuperClass : NSDeprecatedSuperClass {
}
// Tests synthesis of materializeForSet
class ClassWithLimitedAvailabilityAccessors {
var limitedGetter: Int {
@available(OSX, introduced: 52)
get { return 10 }
set(newVal) {}
}
var limitedSetter: Int {
get { return 10 }
@available(OSX, introduced: 52)
set(newVal) {}
}
}
@available(*, unavailable)
func unavailableFunction() -> Int { return 10 } // expected-note 3{{'unavailableFunction()' has been explicitly marked unavailable here}}
class ClassWithReferencesLazyInitializers {
var propWithUnavailableInInitializer: Int = unavailableFunction() // expected-error {{'unavailableFunction()' is unavailable}}
lazy var lazyPropWithUnavailableInInitializer: Int = unavailableFunction() // expected-error {{'unavailableFunction()' is unavailable}}
}
@available(*, unavailable)
func unavailableUseInUnavailableFunction() {
// Diagnose references to unavailable functions in non-implicit code
// as errors
unavailableFunction() // expected-error {{'unavailableFunction()' is unavailable}} expected-warning {{result of call to 'unavailableFunction()' is unused}}
}
@available(OSX 52, *)
func foo() {
let _ = SubOfOtherWithInit()
}
|