Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,17 @@ bool MissingConformanceFailure::diagnoseAsError() {
};

// Limit this to `Equatable` and `Comparable` protocols for now.
auto *protocol = getRHS()->castTo<ProtocolType>()->getDecl();
if (isEnumWithAssociatedValues(getLHS()) &&
(protocol->isSpecificProtocol(KnownProtocolKind::Equatable) ||
protocol->isSpecificProtocol(KnownProtocolKind::Comparable))) {
if (RequirementFailure::diagnoseAsError()) {
auto opName = getOperatorName(expr);
emitDiagnostic(diag::no_binary_op_overload_for_enum_with_payload,
opName->str());
return true;
if (auto *protocolTy = getRHS()->getAs<ProtocolType>()) {
auto *protocol = protocolTy->getDecl();
if (isEnumWithAssociatedValues(getLHS()) &&
(protocol->isSpecificProtocol(KnownProtocolKind::Equatable) ||
protocol->isSpecificProtocol(KnownProtocolKind::Comparable))) {
if (RequirementFailure::diagnoseAsError()) {
auto opName = getOperatorName(expr);
emitDiagnostic(diag::no_binary_op_overload_for_enum_with_payload,
opName->str());
return true;
}
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions stdlib/public/core/Equatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 changes: 36 additions & 0 deletions test/embedded/anyobject.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}