Skip to content

[SR-14795] Unable to conform to Comparable protocol when nested #57144

@swift-ci

Description

@swift-ci
Previous ID SR-14795
Radar None
Original Reporter robdashnash (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 12.5 (12E262)
Swift 5.4
MacOS 11.4

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: a83094320601a7e3537a07f9a2558473

relates to:

  • SR-3092 Function-level nested types cannot conform to Equatable

Issue Description:

Attempts to conform to comparable fail, when the class declaration is nested within a test.

func testA() throws {
        
        final class Property: Comparable {
            
            let id: UUID
            let address: String
            let date: Date
                        
            static func < (lhs: Property, rhs: Property) -> Bool {
                lhs.date > rhs.date
            }
            
            static func == (lhs: Property, rhs: Property) -> Bool {
                lhs.id == rhs.id
            }
        }

        // test stuff here
}
Type 'Property' does not conform to protocol 'Equatable'.  
Type 'Property' does not conform to protocol 'Comparable'.

If I cut and paste the property class code to a global scope, it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesnested typesFeature: nested typesoperatorsFeature: operatorsswift 5.4type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions