mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
133 lines
6.0 KiB
Swift
133 lines
6.0 KiB
Swift
// RUN: %target-typecheck-verify-swift -enable-experimental-feature SuppressedAssociatedTypes
|
|
|
|
protocol U {}
|
|
|
|
enum Maybe<Thing: ~Copyable> : ~Copyable {}
|
|
|
|
func more() {
|
|
let _: any ~Copyable = 19
|
|
|
|
let _: any ~Equatable = 19 // expected-error@:14 {{type 'Equatable' cannot be suppressed}}
|
|
|
|
let _: any (~Copyable & ~Equatable) // expected-error{{type 'Equatable' cannot be suppressed}}
|
|
|
|
let _: ~Any // expected-error {{type 'Any' cannot be suppressed}}
|
|
let _: ~AnyObject // expected-error {{type 'AnyObject' cannot be suppressed}}
|
|
}
|
|
|
|
struct S4: ~(Copyable & Equatable) {} // expected-error {{conformance to 'Equatable' cannot be suppressed}}
|
|
|
|
func blah<T>(_ t: borrowing T) where T: ~Copyable,
|
|
T: ~Hashable {} // expected-error@:41 {{type 'Hashable' cannot be suppressed}}
|
|
|
|
func foo<T: ~Copyable>(x: borrowing T) {}
|
|
|
|
struct Buurap<T: ~Copyable> where T: ~Copyable {}
|
|
|
|
struct ExtraNoncopyStruct: ~Copyable, ~Copyable {}
|
|
struct ExtraNoncopyEnum: ~Copyable, ~Copyable {}
|
|
|
|
protocol ExtraNoncopyProto: ~Copyable, ~Copyable {}
|
|
|
|
protocol Foo: ~Copyable
|
|
where Self: ~Copyable {
|
|
|
|
associatedtype Touch : ~Copyable,
|
|
~Copyable
|
|
|
|
func test<T>(_ t: T) where T: ~Self // expected-error {{type 'Self' cannot be suppressed}}
|
|
}
|
|
|
|
protocol Sando { func make() }
|
|
|
|
class C: ~Copyable, // expected-error {{classes cannot be '~Copyable'}}
|
|
~Sando // expected-error {{type 'Sando' cannot be suppressed}}
|
|
{}
|
|
|
|
public struct MoveOnlyS1<T> : ~Copyable { /*deinit {}*/ }
|
|
public struct MoveOnlyS2<T: Equatable> : ~Copyable { /*deinit {}*/ }
|
|
public struct MoveOnlyS3<T: ~Copyable> : ~Copyable { /*deinit {}*/ }
|
|
|
|
protocol Rope<Element>: Hashable, ~Copyable { // expected-error {{'Self' required to be 'Copyable' but is marked with '~Copyable'}}
|
|
associatedtype Element: ~Copyable
|
|
}
|
|
|
|
extension S: ~Copyable {} // expected-error {{cannot suppress '~Copyable' in extension}}
|
|
|
|
struct S: ~U, // expected-error {{type 'U' cannot be suppressed}}
|
|
~Copyable {}
|
|
|
|
func greenBay<each T: ~Copyable>(_ r: repeat each T) {} // expected-error{{cannot suppress '~Copyable' on type 'each T'}}
|
|
// expected-error@-1 {{'each T' required to be 'Copyable' but is marked with '~Copyable'}}
|
|
|
|
typealias Clone = Copyable
|
|
func dup<D: ~Clone>(_ d: D) {}
|
|
// expected-error@-1 {{parameter of noncopyable type 'D' must specify ownership}}
|
|
// expected-note@-2 {{add 'borrowing'}}
|
|
// expected-note@-3 {{add 'inout'}}
|
|
// expected-note@-4 {{add 'consuming'}}
|
|
|
|
// expected-error@+2 {{parameter of noncopyable type 'some ~Copyable' must specify ownership}}
|
|
// expected-error@+1 {{parameter of noncopyable type 'some ~Clone' must specify ownership}}
|
|
func superb(_ thing: some ~Copyable, thing2: some ~Clone) {}
|
|
// expected-note@-1 2{{add 'borrowing'}}
|
|
// expected-note@-2 2{{add 'inout'}}
|
|
// expected-note@-3 2{{add 'consuming'}}
|
|
|
|
func ownership1(_ t: borrowing any ~Equatable) {} // expected-error {{type 'Equatable' cannot be suppressed}}
|
|
|
|
func ownership2(_ t: ~ borrowing Int) {} // expected-error {{cannot find type 'borrowing' in scope}}
|
|
// expected-error@-1 {{unnamed parameters must be written with the empty name '_'}}
|
|
// expected-error@-2 {{expected ',' separator}}
|
|
|
|
func ownership3(_ t: consuming some ~Clone) {}
|
|
|
|
func what(one: ~Copyable..., // expected-error {{noncopyable type '~Copyable' cannot be used within a variadic type yet}}
|
|
two: ~(Copyable...) // expected-error {{variadic parameter cannot appear outside of a function parameter list}}
|
|
// expected-error@-1 {{parameter of noncopyable type '~Copyable' must specify ownership}}
|
|
// expected-note@-2{{add 'borrowing' for an immutable reference}}
|
|
// expected-note@-3{{add 'inout' for a mutable reference}}
|
|
// expected-note@-4{{add 'consuming' to take the value from the caller}}
|
|
) {}
|
|
|
|
struct A { struct B { struct C {} } }
|
|
|
|
typealias Z0 = (~Copyable).Type // expected-error{{constraint that suppresses conformance requires 'any'}}{{17-17=any }}
|
|
typealias Z1 = ~Copyable.Type // expected-error{{constraint that suppresses conformance requires 'any'}}{{16-16=any }}
|
|
typealias Z2 = ~A.B.C // expected-error {{type 'A.B.C' cannot be suppressed}}
|
|
typealias Z3 = ~A? // expected-error {{type 'A?' cannot be suppressed}}
|
|
typealias Z4 = ~Rope<Int> // expected-error {{type 'Rope<Int>' cannot be suppressed}}
|
|
typealias Z5 = (~Int) -> Void // expected-error {{type 'Int' cannot be suppressed}}
|
|
typealias Z6 = ~() -> () // expected-error {{single argument function types require parentheses}}
|
|
// expected-error@-1 {{type '()' cannot be suppressed}}
|
|
typealias Z7 = ~(Copyable & Hashable) // expected-error {{type 'Hashable' cannot be suppressed}}
|
|
typealias Z8 = ~Copyable & Hashable // expected-error {{composition cannot contain '~Copyable' when another member requires 'Copyable'}}
|
|
|
|
struct NotAProtocol {}
|
|
|
|
struct Bad: ~NotAProtocol {} // expected-error {{type 'NotAProtocol' cannot be suppressed}}
|
|
|
|
|
|
struct X<T: ~Copyable>: ~Copyable { }
|
|
|
|
func typeInExpression() {
|
|
_ = [~Copyable]() // expected-error{{type '~Copyable' does not conform to protocol 'Copyable'}}
|
|
_ = X<any ~Copyable>()
|
|
|
|
_ = X<any ~Copyable & Foo>()
|
|
_ = X<any Foo & ~Copyable>()
|
|
|
|
_ = X<(borrowing any ~Copyable) -> Void>()
|
|
|
|
_ = ~Copyable.self // expected-error{{unary operator '~' cannot be applied to an operand of type '(any Copyable).Type'}}
|
|
_ = (~Copyable).self // expected-error{{constraint that suppresses conformance requires 'any'}}{{8-8=any }}
|
|
_ = (any ~Copyable).self
|
|
}
|
|
|
|
func param1(_ t: borrowing ~Copyable) {} // expected-error{{constraint that suppresses conformance requires 'any'}}{{28-28=any }}
|
|
func param2(_ t: ~Copyable.Type) {} // expected-error{{constraint that suppresses conformance requires 'any'}}{{18-18=any }}
|
|
func param3(_ t: borrowing any ~Copyable) {}
|
|
func param4(_ t: any ~Copyable.Type) {}
|
|
|
|
func param3(_ t: borrowing ExtraNoncopyProto & ~Copyable) {} // expected-error{{constraint that suppresses conformance requires 'any'}}{{28-28=any }}
|