mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
stdlib: Use the original === and !== operators on embedded
It seems that the restriction preventing these from working was lifted. The behavioral difference is that in Swift 5 mode, we don't actually open AnyObject like this, so the old operator could not be used with class-bound existentials. I added a trivial test case just to ensure that calls to === type check correctly in both language modes. Fixes rdar://156095800.
This commit is contained in:
@@ -271,7 +271,7 @@ public func === (lhs: AnyObject?, rhs: AnyObject?) -> Bool {
|
||||
#else
|
||||
@inlinable // trivial-implementation
|
||||
@safe
|
||||
public func ===<T: AnyObject, U: AnyObject>(lhs: T?, rhs: U?) -> Bool {
|
||||
public func === (lhs: AnyObject?, rhs: AnyObject?) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case let (l?, r?):
|
||||
return Builtin.bridgeToRawPointer(l) == Builtin.bridgeToRawPointer(r)
|
||||
@@ -293,14 +293,7 @@ public func ===<T: AnyObject, U: AnyObject>(lhs: T?, rhs: U?) -> Bool {
|
||||
/// - Parameters:
|
||||
/// - lhs: A reference to compare.
|
||||
/// - rhs: Another reference to compare.
|
||||
#if !$Embedded
|
||||
@inlinable // trivial-implementation
|
||||
public func !== (lhs: AnyObject?, rhs: AnyObject?) -> Bool {
|
||||
return !(lhs === rhs)
|
||||
}
|
||||
#else
|
||||
@inlinable // trivial-implementation
|
||||
public func !==<T: AnyObject, U: AnyObject>(lhs: T, rhs: U) -> Bool {
|
||||
return !(lhs === rhs)
|
||||
}
|
||||
#endif
|
||||
|
||||
36
test/embedded/anyobject.swift
Normal file
36
test/embedded/anyobject.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -swift-version 5) | %FileCheck %s
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -O -swift-version 5) | %FileCheck %s
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -Osize -swift-version 5) | %FileCheck %s
|
||||
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -swift-version 6) | %FileCheck %s
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -O -swift-version 6) | %FileCheck %s
|
||||
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -wmo -Osize -swift-version 6) | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: optimized_stdlib
|
||||
// REQUIRES: swift_feature_Embedded
|
||||
|
||||
protocol P: AnyObject {}
|
||||
|
||||
class C: P {}
|
||||
|
||||
@main
|
||||
struct Main {
|
||||
static func main() {
|
||||
let p1: any P = C()
|
||||
let p2: any P = C()
|
||||
let p3 = p1
|
||||
|
||||
// CHECK: false
|
||||
print(p1 === p2)
|
||||
print(p2 === p1)
|
||||
// CHECK: true
|
||||
print(p1 === p3)
|
||||
print(p3 === p1)
|
||||
// CHECK: false
|
||||
print(p2 === p3)
|
||||
print(p3 === p2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user