mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Generic methods declared in protocols (and extensions thereof) cannot be used on existential values, because there is no way to specialize them for all potential types. Diagnose such cases in Embedded Swift mode and via `-Wwarning EmbeddedRestrictions`. This adds a bunch more warnings to the standard library that we'll need to clean up, probably by `#if`'ing more code out. Part of rdar://119383905.
19 lines
703 B
Swift
19 lines
703 B
Swift
// RUN: %target-swift-emit-ir -parse-as-library -module-name main -verify %s -enable-experimental-feature Embedded -wmo
|
|
|
|
// REQUIRES: swift_in_compiler
|
|
// REQUIRES: optimized_stdlib
|
|
// REQUIRES: swift_feature_Embedded
|
|
|
|
public protocol MyProtocol: AnyObject {
|
|
func foo<T: BinaryInteger>(ptr: UnsafeMutableRawPointer?, value: T)
|
|
}
|
|
|
|
func test_some(p: some MyProtocol) {
|
|
p.foo(ptr: nil, value: 0) // expected-error {{a protocol type cannot contain a generic method 'foo(ptr:value:)' in embedded Swift}}
|
|
}
|
|
|
|
public func test_any(p: any MyProtocol) {
|
|
test_some(p: p)
|
|
// expected-warning@-1{{cannot use generic global function 'test_some(p:)' on a value of type 'any MyProtocol' in Embedded Swift}}
|
|
}
|