swift icon indicating copy to clipboard operation
swift copied to clipboard

Conditional cast from 'any Error' to 'any Equatable' always succeeds... but doesn't

Open jasonbobier opened this issue 2 years ago • 1 comments

Description

The compiler tells me that the cast from 'any Error' to 'any Equatable' always succeeds, but then tells me that it doesn't.

Reproduction

enum SomeError: Error {
	case error
}

let t: any Error = SomeError.error

func needsEquatable<E: Equatable>(e: E) {
}

if let t = t as? (any Equatable) { // Warning: Conditional cast from 'any Error' to 'any Equatable' always succeeds
	needsEquatable(e: t)
}

needsEquatable(e: t) // Error: Global function 'needsEquatable(e:)' requires that 'E' conform to 'Equatable'

Expected behavior

I don't think that Error is Equatable, so the warning is probably wrong.

Environment

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1) Target: arm64-apple-macosx14.0

Additional information

No response

jasonbobier avatar Nov 30 '23 07:11 jasonbobier

@AnthonyLatsis this one seems to have been overlooked. This is still an issue in Xcode Version 16.0 beta 4 (16A5211f).

jasonbobier avatar Jul 30 '24 10:07 jasonbobier

+1

nonameplum avatar Sep 30 '24 11:09 nonameplum

seeing similar issue here but when trying to cast any Error to CustomDebugStringConvertible

fzy-github avatar Jul 01 '25 14:07 fzy-github

CC: @xedin

tbkka avatar Jul 01 '25 15:07 tbkka

This is still an issue as of Xcode Version 26.0.1 (17A400)

jasonbobier avatar Oct 19 '25 15:10 jasonbobier