Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing compiler error "Value of optional type 'T?' must be unwrapped to a value of type 'T'" when comparing optional with non-optional #76202

Open
nickasd opened this issue Sep 1, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@nickasd
Copy link

nickasd commented Sep 1, 2024

Description

When comparing an optional with a non-optional with == where the type doesn't conform to Equatable, the compiler shows a confusing error Value of optional type 'T?' must be unwrapped to a value of type 'T'.

Reproduction

class MyClass<T: RawRepresentable> where T.RawValue == String {
    
    func asd(a: T?) {
        let b = a!
        print(a == b) // compiler error: Value of optional type 'T?' must be unwrapped to a value of type 'T'
    }
    
}

Expected behavior

The compiler should show the error

Operator function '==' requires that 'T' conform to 'Equatable'

which correctly appears when removing the constraint where T.RawValue == String.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@nickasd nickasd added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant