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 110 111 112
|
// RUN: %target-typecheck-verify-swift -swift-version 4
let x: Int = 1
let y: Int = x.self
let int: Int.Type = Int.self
// SE-0071 - Allow (most) keywords in member references
// https://github.com/apple/swift-evolution/blob/master/proposals/0071-member-keywords.md
struct SE0071Struct {
var `default` : Int
}
func f1(a : SE0071Struct) -> Int {
return a.default
}
func f2(a : SE0071Struct) -> Int {
return a.`default`
}
enum SE0071Enum {
case `case`
}
func f2() -> SE0071Enum {
return .case
}
class SE0071Base {
func `default`() {}
}
class SE0071Derived : SE0071Base {
func zonk() {
super.default()
}
}
// https://github.com/apple/swift/issues/45633
// Diagnostics when accessing deinit
class Base {}
class Derived: Base {
deinit {
super.deinit() // expected-error {{deinitializers cannot be accessed}}
}
}
do {
let derived = Derived()
derived.deinit() // expected-error {{deinitializers cannot be accessed}}
derived.deinit // expected-error {{deinitializers cannot be accessed}}
Derived.deinit() // expected-error {{deinitializers cannot be accessed}}
}
// Allow deinit functions in classes
class ClassWithDeinitFunc {
func `deinit`() {
}
func `deinit`(a: Base) {
}
}
class ClassWithDeinitMember {
var `deinit`: Base?
}
do {
let instanceWithDeinitFunc = ClassWithDeinitFunc()
instanceWithDeinitFunc.deinit()
_ = instanceWithDeinitFunc.deinit(a:)
_ = instanceWithDeinitFunc.deinit as () -> Void
let instanceWithDeinitMember = ClassWithDeinitMember()
_ = instanceWithDeinitMember.deinit
}
// https://github.com/apple/swift/issues/48285
// Fix variable name in nested static value
struct S {
struct A {
struct B {}
}
}
extension S.A.B {
private static let x: Int = 5
func f() -> Int {
return x // expected-error {{static member 'x' cannot be used on instance of type 'S.A.B'}} {{12-12=S.A.B.}}
}
}
// Static function in protocol should have `Self.` instead of its protocol name
protocol P {}
extension P {
static func f() {}
func g() {
f() // expected-error {{static member 'f' cannot be used on instance of type 'Self'}} {{5-5=Self.}}
}
}
|