Files
swift-mirror/test/Parse/discard.swift
Kavon Farvardin 3e4bc82aa8 rename _forget to discard; deprecate _forget
SE-390 concluded with choosing the keyword discard rather than forget for
the statement that disables the deinit of a noncopyable type. This commit
adds parsing support for `discard self` and adds a deprecation warning for
`_forget self`.

rdar://108859077
2023-05-08 21:42:19 -07:00

76 lines
1.4 KiB
Swift

// RUN: %swift-frontend -dump-parse -verify %s > /dev/null
func discard<T>(_ t: T) {}
func a() {
discard case // expected-error {{'case' label can only appear inside a 'switch' statement}}
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
}
func b() {
discard 124 // expected-error {{consecutive statements on a line must be separated by ';'}}
}
func c() {
discard where 5 == 0 // expected-error {{expected expression}}
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
}
func c() {
// sticking a let here to ensure the parser is treating this like an expr.
let _ = discard ++ something
}
func c() {
let _ = discard self // expected-error {{consecutive statements on a line must be separated by ';'}}
}
func c() {
discard Self
}
func c() {
discard self
}
func c() {
discard `self`
}
func c() {
discard switch // expected-error {{expected expression in 'switch' statement}}
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
}
func c() {
discard SarahMarshall
}
func c() {
discard x.y.z
}
func c() {
discard discard self // expected-error {{consecutive statements on a line must be separated by ';'}}
}
class discard {
func discard() {
discard discard(self)
let _ = discard()
let _ = discard{
discard {
discard itALL
}
}
}
var x: Int {
get {
discard self.x()
}
}
}