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
|
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck -F %S/Inputs/frameworks %s 2>&1 | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-PUBLIC %s
// RUN: echo '#import <CategoryOverrides/Private.h>' > %t.h
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -F %S/Inputs/frameworks -enable-objc-interop -import-objc-header %t.h %s 2>&1 | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-PRIVATE %s --allow-empty
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -emit-pch -F %S/Inputs/frameworks -o %t.pch %t.h
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -F %S/Inputs/frameworks -enable-objc-interop -import-objc-header %t.pch %s 2>&1 | %FileCheck --allow-empty -check-prefix=CHECK -check-prefix=CHECK-PRIVATE %s
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -F %S/Inputs/frameworks -enable-objc-interop -import-objc-header %t.h -pch-output-dir %t/pch %s 2>&1 | %FileCheck --allow-empty -check-prefix=CHECK -check-prefix=CHECK-PRIVATE %s
import CategoryOverrides
// Nail down some emergent behaviors of the Clang Importer's override checking:
// A category declared in a (private) header can happen to double-import a property
// and a function with the same name - both before and after omit-needless-words -
// as long as they have different contextual types.
//
// This configuration appears as an undiagnosed redeclaration of a property and
// function, which is illegal.
func colors() {
// CHECK-PUBLIC: cannot call value of non-function type 'MyColor?'
// CHECK-PRIVATE-NOT: cannot call value of non-function type 'MyColor?'
let _ : MyColor = MyColor.systemRed
let _ : MyColor = MyColor.systemRed()!
}
// Another manifestation of the above for an instance property this time.
func structs(_ base: MyBaseClass, _ derived: MyDerivedClass) {
// CHECK-PUBLIC: cannot call value of non-function type 'SomeStruct'
// CHECK-PRIVATE-NOT: cannot call value of non-function type 'SomeStruct'
let _ : SomeStruct = base.myStructure
let _ : SomeStruct = base.myStructure()
// CHECK-PUBLIC: cannot call value of non-function type 'SomeStruct'
// CHECK-PRIVATE-NOT: cannot call value of non-function type 'SomeStruct'
let _ : SomeStruct = derived.myStructure
let _ : SomeStruct = derived.myStructure()
}
// A category declared in a (private) header can introduce overrides of a property
// that is otherwise not declared in a base class.
//
// This configuration appears as an undiagnosed override in a Swift extension,
// which is illegal.
func takesADerivedClass(_ x: MyDerivedClass) {
// CHECK-PUBLIC-NOT: has no member 'derivedMember'
// CHECK-PRIVATE-NOT: has no member 'derivedMember'
x.derivedMember = Base()
}
func takesABaseClass(_ x: MyBaseClass) {
// CHECK-PUBLIC: has no member 'derivedMember'
// CHECK-PRIVATE-NOT: has no member 'derivedMember'
x.derivedMember = Base()
}
// A category declared in a (private) header can introduce overrides of a
// property that has mismatched Swift naming conventions. If we see a
// non-__attribute__((swift_private)) decl, sometimes it comes in too.
extension Refinery {
public enum RefinedSugar {
case caster
case grantulated
case confectioners
case cane
case demerara
case turbinado
}
public var sugar: Refinery.RefinedSugar {
return .caster // RefinedSugar(self.__sugar)
}
}
func takesARefinery(_ x: Refinery) {
// CHECK: cannot assign to property: 'sugar' is a get-only property
x.sugar = .caster
}
func takesAnExtraRefinery(_ x: ExtraRefinery) {
// CHECK: has no member 'sugar'
x.sugar = .caster
x.setSugar(0)
}
func nullabilityRefinementProto(_ x: MyBaseClass) {
// CHECK-PUBLIC: has no member 'requirement'
// CHECK-PRIVATE-NOT: has no member 'requirement'
// CHECK-PRIVATE-NOT: value of optional type 'Base?'
let _ : Base = x.requirement
}
func readwriteRefinementProto(_ x: MyDerivedClass) {
// CHECK-PUBLIC: has no member 'answer'
// CHECK-PRIVATE-NOT: has no member 'answer'
if x.answer == 0 {
// CHECK-PUBLIC: has no member 'answer'
// CHECK-PRIVATE-NOT: has no member 'answer'
x.answer = 42
}
}
|