Skip to content

Commit c317fda

Browse files
committed
Include test of error on declaring property with type Self
1 parent cd1656c commit c317fda

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/type/self.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,27 @@ enum E {
151151
return .e
152152
}
153153
}
154+
155+
class A1 {
156+
required init() {}
157+
func copy() -> Self {
158+
let copy = Self.init()
159+
return copy
160+
}
161+
162+
var copied: Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'A1'?}}
163+
let copy = Self.init()
164+
return copy
165+
}
166+
}
167+
168+
class B1: A1 {
169+
override func copy() -> Self {
170+
let copy = super.copy() as! Self // supported
171+
return copy
172+
}
173+
override var copied: Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'B1'?}}
174+
let copy = super.copied as! Self // unsupported
175+
return copy
176+
}
177+
}

0 commit comments

Comments
 (0)