mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
When a witness is unsafe and its corresponding requirement is not unsafe, the conformance itself needs to be determined to be unsafe. When doing this check, account for the fact that the requirement might be implicitly unsafe, i.e., it uses unsafe types. In such cases, the requirement is effectively unsafe, so the unsafe witness to it does not make the conformance unsafe. Therefore, suppress the diagnostic. This accounts for cases where the protocol comes from a module that didn't enable strict memory safety checking, or didn't suppress all warnings related to it, as well as cases where substitution of type witnesses introduces the unsafe type. The same thing occurs with overriding a method: an unsafe override of a method that involves unsafe types (but was not marked @unsafe for whatever reason) does not make the subclassing itself unsafe, so don't diagnose it as such.
24 lines
506 B
Swift
24 lines
506 B
Swift
@unsafe public struct PointerType { } // expected-note{{'PointerType' declared here}}
|
|
|
|
public typealias UnsafeTypeAlias = PointerType
|
|
|
|
public func getPointers() -> [PointerType] { [] }
|
|
|
|
public struct HasAPointerType {
|
|
public typealias Ptr = PointerType
|
|
}
|
|
|
|
public protocol Ptrable {
|
|
associatedtype Ptr
|
|
}
|
|
|
|
extension HasAPointerType: Ptrable { }
|
|
|
|
public protocol HasUnsafeRequirement {
|
|
func f(_: PointerType)
|
|
}
|
|
|
|
open class SuperclassWithUnsafeMethod {
|
|
open func implicitlyUnsafe(_: PointerType) { }
|
|
}
|