Files
swift-mirror/test/Unsafe/Inputs/unsafe_swift_decls.swift
Doug Gregor 4b3c18de41 Account for implicit unsafety in unsafe witness and override checks
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.
2024-12-24 09:32:05 -08:00

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