Skip to content

Compiler error when using not equal operator on static optional variable #86227

@nickasd

Description

@nickasd

Description

I would expect the code below to compile successfully, but I get an error

Value of optional type 'A?' must be unwrapped to a value of type 'A'

When changing != to == or .shared to A.shared it compiles.

Reproduction

class A: Equatable {
    static func == (lhs: A, rhs: A) -> Bool {
        lhs === rhs
    }
    
    static var shared: A?
}

let a = A()
print(a != .shared)

Expected behavior

No compiler error.

Environment

swift-driver version: 1.127.14.1 Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
Target: arm64-apple-macosx26.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions