Files
swift-mirror/test/Inputs/clang-importer-sdk/swift-modules/ObjectiveC.swift
Allan Shortlidge 8846f4e691 [SE-0364] Handle retroactive conformance for types and protocols from underlying modules.
SE-0364 was implemented to discourage "retroactive" conformances that might
conflict with conformances that could be introduced by other modules in the
future. These diagnostics should not apply to conformances that involve types
and protocols imported from the underlying clang module of a Swift module since
the two modules are assumed to be developed in tandem by the same owners,
despite technically being separate modules from the perspective of the
compiler.

The diagnostics implemented in https://github.com/apple/swift/pull/36068 were
designed to take underlying clang modules into account. However, the
implementation assumed that `ModuleDecl::getUnderlyingModuleIfOverlay()` would
behave as expected when called on the Swift module being compiled.
Unfortunately, it would always return `nullptr` and thus conformances involving
the underlying clang module are being diagnosed unexpectedly.

The fix is to make `ModuleDecl::getUnderlyingModuleIfOverlay()` behave as
expected when it is made up of `SourceFile`s.

Resolves rdar://121478556
2024-02-01 10:43:53 -08:00

99 lines
2.1 KiB
Swift

@_exported import ObjectiveC // Clang module
// The iOS/arm64 target uses _Bool for Objective-C's BOOL. We include
// x86_64 here as well because the iOS simulator also uses _Bool.
public struct ObjCBool {
#if (os(macOS) && arch(x86_64)) || (os(iOS) && (arch(i386) || arch(arm) || targetEnvironment(macCatalyst)))
// On macOS and 32-bit iOS, Objective-C's BOOL type is a "signed char".
private var value: UInt8
public init(_ value: Bool) {
self.value = value ? 1 : 0
}
/// Allow use in a Boolean context.
public var boolValue: Bool {
return value != 0
}
#else
// Everywhere else it is C/C++'s "Bool"
private var value: Bool
public init(_ value: Bool) {
self.value = value
}
public var boolValue: Bool {
return value
}
#endif
}
extension ObjCBool : ExpressibleByBooleanLiteral {
public init(booleanLiteral: Bool) {
self.init(booleanLiteral)
}
}
public struct Selector : ExpressibleByStringLiteral {
private var ptr : OpaquePointer
public init(_ value: String) {
self.init(stringLiteral: value)
}
public init(unicodeScalarLiteral value: String) {
self.init(stringLiteral: value)
}
public init(extendedGraphemeClusterLiteral value: String) {
self.init(stringLiteral: value)
}
public init (stringLiteral value: String) {
self = sel_registerName(value)
}
public func hash(into hasher: inout Hasher) {
hasher.combine(ptr)
}
}
extension Selector : Equatable, Hashable {}
public func ==(lhs: Selector, rhs: Selector) -> Bool {
return sel_isEqual(lhs, rhs)
}
public struct NSZone {
public var pointer : OpaquePointer
}
public func _convertBoolToObjCBool(_ x: Bool) -> ObjCBool {
return ObjCBool(x)
}
public func _convertObjCBoolToBool(_ x: ObjCBool) -> Bool {
return x.boolValue
}
public func ~=(x: NSObject, y: NSObject) -> Bool {
return true
}
extension NSObject : Equatable, Hashable {
public static func == (lhs: NSObject, rhs: NSObject) -> Bool {
return lhs.isEqual(rhs)
}
public var hashValue: Int {
return hash
}
public func hash(into hasher: inout Hasher) {
hasher.combine(hash)
}
}