Files
swift-mirror/test/embedded/existential-generic-error.swift
Doug Gregor ade6e55b0c [Embedded] Diagnose uses of generic methods on existential values
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.
2025-09-18 10:05:35 -07:00

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}}
}