Skip to content

[SR-3092] Function-level nested types cannot conform to Equatable #45682

@swift-ci

Description

@swift-ci
Previous ID SR-3092
Radar rdar://problem/44479781
Original Reporter ellneal (JIRA User)
Type Bug
Status Reopened
Resolution
Environment

Swift build number: Xcode 8.1 (8B62) embedded version
Target OS: iOS
Build OS: macOS Sierra 16A323
Build Tool: Xcode Version 8.1 (8B62)

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

md5: f04b40d7c56cb16b9b79a99c8f79b080

is duplicated by:

  • SR-3875 Can't conform to Equatable when type is inside a function
  • SR-5939 Type nested in function cannot satisfy operator protocol requirement
  • SR-6526 Can't conform a type declared inside a function to Equatable
  • SR-8696 Types nested in functions and their operator functions.
  • SR-9956 classes defined inside functions can't be made to conform to Equatable?
  • SR-11482 Some protocols cannot be conformed by code-block-local types
  • SR-13398 Nested Equatable synthesis cannot be overidden.

relates to:

  • SR-14795 Unable to conform to Comparable protocol when nested
  • SR-8696 Types nested in functions and their operator functions.

Issue Description:

The compiler fails to compile a struct that conforms to Equatable inside a function.

struct RootLevelStruct: Equatable { // compiles fine
    static func ==(lhs: RootLevelStruct, rhs: RootLevelStruct) -> Bool {
        return false
    }
}

class MyClass {
    struct ClassLevelStruct: Equatable { // compiles fine
        static func ==(lhs: ClassLevelStruct, rhs: ClassLevelStruct) -> Bool {
            return false
        }
    }
    
    func someFunction() {
        struct FunctionLevelStruct: Equatable { // Error: Protocol 'Equatable' can only be used a generic constraint because it has Self or associated type requirements
            static func ==(lhs: FunctionLevelStruct, rhs: FunctionLevelStruct) -> Bool {
                return false
            }
        }
    }
}

Metadata

Metadata

Assignees

Labels

compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesnested typesFeature: nested typesoperatorsFeature: operatorsswift 3.0type 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