Navigation Menu

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

[SR-3875] Can't conform to Equatable when type is inside a function #46460

Closed
ankitspd opened this issue Feb 6, 2017 · 2 comments
Closed

[SR-3875] Can't conform to Equatable when type is inside a function #46460

ankitspd opened this issue Feb 6, 2017 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances duplicate Resolution: Duplicates another issue nested types Feature: nested types operators Feature: operators type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error

Comments

@ankitspd
Copy link
Member

ankitspd commented Feb 6, 2017

Previous ID SR-3875
Radar None
Original Reporter @aciidb0mb3r
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @DougGregor
Priority Medium

md5: 4ff50a3c78036f702bd1ab23bd0e6628

duplicates:

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

Issue Description:

func foo() {
    struct Bar: Equatable {
        static func ==(lhs: Bar, rhs: Bar) -> Bool {
            return true
        }
    }
}
Playground execution failed: error: MyPlayground.playground:2:12: error: type 'Bar' does not conform to protocol 'Equatable'
    struct Bar: Equatable {
           ^

Swift.Equatable:149:24: note: protocol requires function '==' with type '(Bar, Bar) -> Bool'; do you want to add a stub?
    public static func ==(lhs: Self, rhs: Self) -> Bool
                       ^

Swift.==:2:13: note: candidate has non-matching type '<Element where Element : Equatable> (ContiguousArray<Element>, ContiguousArray<Element>) -> Bool'
public func ==<Element>(lhs: ContiguousArray<Element>, rhs: ContiguousArray<Element>) -> Bool where Element : Equatable
            ^

Swift.==:2:13: note: candidate has non-matching type '<Element where Element : Equatable> (ArraySlice<Element>, ArraySlice<Element>) -> Bool'
public func ==<Element>(lhs: ArraySlice<Element>, rhs: ArraySlice<Element>) -> Bool where Element : Equatable
            ^

Swift.==:2:13: note: candidate has non-matching type '<Element where Element : Equatable> (Array<Element>, Array<Element>) -> Bool'
public func ==<Element>(lhs: [Element], rhs: [Element]) -> Bool where Element : Equatable
            ^

Swift.==:1:13: note: candidate has non-matching type '<Pointee> (AutoreleasingUnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool'
public func ==<Pointee>(lhs: AutoreleasingUnsafeMutablePointer<Pointee>, rhs: AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool
            ^

Swift.==:3:13: note: candidate has non-matching type '(Any.Type?, Any.Type?) -> Bool'
public func ==(t0: Any.Type?, t1: Any.Type?) -> Bool
            ^

Swift.==:6:13: note: candidate has non-matching type '<T where T : RawRepresentable, T.RawValue : Equatable> (T, T) -> Bool'
public func ==<T>(lhs: T, rhs: T) -> Bool where T : RawRepresentable, T.RawValue : Equatable
            ^

Swift.==:1:13: note: candidate has non-matching type '<Base where Base : Collection> (LazyDropWhileIndex<Base>, LazyDropWhileIndex<Base>) -> Bool'
public func ==<Base>(lhs: LazyDropWhileIndex<Base>, rhs: LazyDropWhileIndex<Base>) -> Bool where Base : Collection
            ^

Swift.==:5:13: note: candidate has non-matching type '(UInt8, UInt8) -> Bool'
public func ==(lhs: UInt8, rhs: UInt8) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(Int8, Int8) -> Bool'
public func ==(lhs: Int8, rhs: Int8) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(UInt16, UInt16) -> Bool'
public func ==(lhs: UInt16, rhs: UInt16) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(Int16, Int16) -> Bool'
public func ==(lhs: Int16, rhs: Int16) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(UInt32, UInt32) -> Bool'
public func ==(lhs: UInt32, rhs: UInt32) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(Int32, Int32) -> Bool'
public func ==(lhs: Int32, rhs: Int32) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(UInt64, UInt64) -> Bool'
public func ==(lhs: UInt64, rhs: UInt64) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(Int64, Int64) -> Bool'
public func ==(lhs: Int64, rhs: Int64) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(UInt, UInt) -> Bool'
public func ==(lhs: UInt, rhs: UInt) -> Bool
            ^

Swift.==:5:13: note: candidate has non-matching type '(Int, Int) -> Bool'
public func ==(lhs: Int, rhs: Int) -> Bool
            ^

Swift.==:1:13: note: candidate has non-matching type '<T where T : FloatingPoint> (T, T) -> Bool'
public func ==<T>(lhs: T, rhs: T) -> Bool where T : FloatingPoint
            ^

Swift.==:1:13: note: candidate has non-matching type '<Value, Element> (_HeapBuffer<Value, Element>, _HeapBuffer<Value, Element>) -> Bool'
public func ==<Value, Element>(lhs: _HeapBuffer<Value, Element>, rhs: _HeapBuffer<Value, Element>) -> Bool
            ^

Swift.==:1:13: note: candidate has non-matching type '<T where T : BinaryInteger> (T, T) -> Bool'
public func ==<T>(lhs: T, rhs: T) -> Bool where T : BinaryInteger
            ^

Swift.==:1:13: note: candidate has non-matching type '<T, U where T : BinaryInteger, U : BinaryInteger> (T, U) -> Bool'
public func ==<T, U>(lhs: T, rhs: U) -> Bool where T : BinaryInteger, U : BinaryInteger
            ^

Swift.==:1:13: note: candidate has non-matching type '<Header, Element> (ManagedBufferPointer<Header, Element>, ManagedBufferPointer<Header, Element>) -> Bool'
public func ==<Header, Element>(lhs: ManagedBufferPointer<Header, Element>, rhs: ManagedBufferPointer<Header, Element>) -> Bool
            ^

Swift.==:45:13: note: candidate has non-matching type '<T where T : Equatable> (T?, T?) -> Bool'
public func ==<T>(lhs: T?, rhs: T?) -> Bool where T : Equatable
            ^

Swift.==:22:13: note: candidate has non-matching type '<T> (T?, _OptionalNilComparisonType) -> Bool'
public func ==<T>(lhs: T?, rhs: _OptionalNilComparisonType) -> Bool
            ^

Swift.==:22:13: note: candidate has non-matching type '<T> (_OptionalNilComparisonType, T?) -> Bool'
public func ==<T>(lhs: _OptionalNilComparisonType, rhs: T?) -> Bool
            ^

Swift.==:1:13: note: candidate has non-matching type '<Base where Base : Collection> (LazyPrefixWhileIndex<Base>, LazyPrefixWhileIndex<Base>) -> Bool'
public func ==<Base>(lhs: LazyPrefixWhileIndex<Base>, rhs: LazyPrefixWhileIndex<Base>) -> Bool where Base : Collection
            ^

Swift.==:1:13: note: candidate has non-matching type '<T where T : Strideable> (T, T) -> Bool'
public func ==<T>(x: T, y: T) -> Bool where T : Strideable
            ^

Swift.==:20:13: note: candidate has non-matching type '<A, B where A : Equatable, B : Equatable> ((A, B), (A, B)) -> Bool'
public func ==<A, B>(lhs: (A, B), rhs: (A, B)) -> Bool where A : Equatable, B : Equatable
            ^

Swift.==:20:13: note: candidate has non-matching type '<A, B, C where A : Equatable, B : Equatable, C : Equatable> ((A, B, C), (A, B, C)) -> Bool'
public func ==<A, B, C>(lhs: (A, B, C), rhs: (A, B, C)) -> Bool where A : Equatable, B : Equatable, C : Equatable
            ^

Swift.==:20:13: note: candidate has non-matching type '<A, B, C, D where A : Equatable, B : Equatable, C : Equatable, D : Equatable> ((A, B, C, D), (A, B, C, D)) -> Bool'
public func ==<A, B, C, D>(lhs: (A, B, C, D), rhs: (A, B, C, D)) -> Bool where A : Equatable, B : Equatable, C : Equatable, D : Equatable
            ^

Swift.==:20:13: note: candidate has non-matching type '<A, B, C, D, E where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable> ((A, B, C, D, E), (A, B, C, D, E)) -> Bool'
public func ==<A, B, C, D, E>(lhs: (A, B, C, D, E), rhs: (A, B, C, D, E)) -> Bool where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable
            ^

Swift.==:20:13: note: candidate has non-matching type '<A, B, C, D, E, F where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable, F : Equatable> ((A, B, C, D, E, F), (A, B, C, D, E, F)) -> Bool'
public func ==<A, B, C, D, E, F>(lhs: (A, B, C, D, E, F), rhs: (A, B, C, D, E, F)) -> Bool where A : Equatable, B : Equatable, C : Equatable, D : Equatable, E : Equatable, F : Equatable
            ^

Swift.Bool:11:24: note: candidate has non-matching type '(Bool, Bool) -> Bool'
    public static func ==(lhs: Bool, rhs: Bool) -> Bool
                       ^

Swift.Character:2:24: note: candidate has non-matching type '(Character, Character) -> Bool'
    public static func ==(lhs: Character, rhs: Character) -> Bool
                       ^

Swift.ClosedRangeIndex<Bound>:2:24: note: candidate has non-matching type '<Bound> (ClosedRangeIndex<Bound>, ClosedRangeIndex<Bound>) -> Bool'
    public static func ==(lhs: ClosedRangeIndex<Bound>, rhs: ClosedRangeIndex<Bound>) -> Bool
                       ^

Swift.OpaquePointer:2:24: note: candidate has non-matching type '(OpaquePointer, OpaquePointer) -> Bool'
    public static func ==(lhs: OpaquePointer, rhs: OpaquePointer) -> Bool
                       ^

Swift.EmptyCollection<Element>:2:24: note: candidate has non-matching type '<Element> (EmptyCollection<Element>, EmptyCollection<Element>) -> Bool'
    public static func ==(lhs: EmptyCollection<Element>, rhs: EmptyCollection<Element>) -> Bool
                       ^

Swift.LazyFilterIndex<Base>:2:24: note: candidate has non-matching type '<Base> (LazyFilterIndex<Base>, LazyFilterIndex<Base>) -> Bool'
    public static func ==(lhs: LazyFilterIndex<Base>, rhs: LazyFilterIndex<Base>) -> Bool
                       ^

Swift.FlattenCollectionIndex<BaseElements>:2:24: note: candidate has non-matching type '<BaseElements> (FlattenCollectionIndex<BaseElements>, FlattenCollectionIndex<BaseElements>) -> Bool'
    public static func ==(lhs: FlattenCollectionIndex<BaseElements>, rhs: FlattenCollectionIndex<BaseElements>) -> Bool
                       ^

Swift.FlattenBidirectionalCollectionIndex<BaseElements>:2:24: note: candidate has non-matching type '<BaseElements> (FlattenBidirectionalCollectionIndex<BaseElements>, FlattenBidirectionalCollectionIndex<BaseElements>) -> Bool'
    public static func ==(lhs: FlattenBidirectionalCollectionIndex<BaseElements>, rhs: FlattenBidirectionalCollectionIndex<BaseElements>) -> Bool
                       ^

Swift.FloatingPointClassification:36:30: note: candidate has non-matching type '(FloatingPointClassification, FloatingPointClassification) -> Bool'
    infix public static func ==(a: FloatingPointClassification, b: FloatingPointClassification) -> Bool
                             ^

Swift.FloatingPointRoundingRule:121:30: note: candidate has non-matching type '(FloatingPointRoundingRule, FloatingPointRoundingRule) -> Bool'
    infix public static func ==(a: FloatingPointRoundingRule, b: FloatingPointRoundingRule) -> Bool
                             ^

Swift.Set<Element>:9:24: note: candidate has non-matching type '<Element> (Set<Element>, Set<Element>) -> Bool'
    public static func ==(lhs: Set<Element>, rhs: Set<Element>) -> Bool
                       ^

Swift.Dictionary<Key, Value>:2:24: note: candidate has non-matching type '<Key, Value> ([Key : Value], [Key : Value]) -> Bool'
    public static func ==(lhs: [Key : Value], rhs: [Key : Value]) -> Bool
                       ^

Swift.Set<Element>.Index:2:24: note: candidate has non-matching type '<Element> (Set<Element>.Index, Set<Element>.Index) -> Bool'
    public static func ==(lhs: Set<Element>.Index, rhs: Set<Element>.Index) -> Bool
                       ^

Swift.Dictionary<Key, Value>.Index:2:24: note: candidate has non-matching type '<Key, Value> (Dictionary<Key, Value>.Index, Dictionary<Key, Value>.Index) -> Bool'
    public static func ==(lhs: [Key : Value].Index, rhs: [Key : Value].Index) -> Bool
                       ^

Swift.AnyHashable:27:24: note: candidate has non-matching type '(AnyHashable, AnyHashable) -> Bool'
    public static func ==(lhs: AnyHashable, rhs: AnyHashable) -> Bool
                       ^

Swift.ArithmeticOverflow:5:30: note: candidate has non-matching type '(ArithmeticOverflow, ArithmeticOverflow) -> Bool'
    infix public static func ==(a: ArithmeticOverflow, b: ArithmeticOverflow) -> Bool
                             ^

Swift.ObjectIdentifier:3:24: note: candidate has non-matching type '(ObjectIdentifier, ObjectIdentifier) -> Bool'
    public static func ==(x: ObjectIdentifier, y: ObjectIdentifier) -> Bool
                       ^

Swift.Range<Bound>:18:24: note: candidate has non-matching type '<Bound> (Range<Bound>, Range<Bound>) -> Bool'
    public static func ==(lhs: Range<Bound>, rhs: Range<Bound>) -> Bool
                       ^

Swift.CountableRange<Bound>:18:24: note: candidate has non-matching type '<Bound> (CountableRange<Bound>, CountableRange<Bound>) -> Bool'
    public static func ==(lhs: CountableRange<Bound>, rhs: CountableRange<Bound>) -> Bool
                       ^

Swift.ClosedRange<Bound>:15:24: note: candidate has non-matching type '<Bound> (ClosedRange<Bound>, ClosedRange<Bound>) -> Bool'
    public static func ==(lhs: ClosedRange<Bound>, rhs: ClosedRange<Bound>) -> Bool
                       ^

Swift.CountableClosedRange<Bound>:15:24: note: candidate has non-matching type '<Bound> (CountableClosedRange<Bound>, CountableClosedRange<Bound>) -> Bool'
    public static func ==(lhs: CountableClosedRange<Bound>, rhs: CountableClosedRange<Bound>) -> Bool
                       ^

Swift._MirrorDisposition:25:30: note: candidate has non-matching type '(_MirrorDisposition, _MirrorDisposition) -> Bool'
    infix public static func ==(a: _MirrorDisposition, b: _MirrorDisposition) -> Bool
                             ^

Swift.ReversedIndex:7:24: note: candidate has non-matching type '<Base> (ReversedIndex<Base>, ReversedIndex<Base>) -> Bool'
    public static func ==(lhs: ReversedIndex<Base>, rhs: ReversedIndex<Base>) -> Bool
                       ^

Swift.ReversedRandomAccessIndex:7:24: note: candidate has non-matching type '<Base> (ReversedRandomAccessIndex<Base>, ReversedRandomAccessIndex<Base>) -> Bool'
    public static func ==(lhs: ReversedRandomAccessIndex<Base>, rhs: ReversedRandomAccessIndex<Base>) -> Bool
                       ^

Swift.String:2:24: note: candidate has non-matching type '(String, String) -> Bool'
    public static func ==(lhs: String, rhs: String) -> Bool
                       ^

Swift.String.CharacterView.Index:2:24: note: candidate has non-matching type '(String.Index, String.Index) -> Bool'
    public static func ==(lhs: String.Index, rhs: String.Index) -> Bool
                       ^

Swift.String.UnicodeScalarView.Index:2:24: note: candidate has non-matching type '(String.UnicodeScalarView.Index, String.UnicodeScalarView.Index) -> Bool'
    public static func ==(lhs: String.UnicodeScalarView.Index, rhs: String.UnicodeScalarView.Index) -> Bool
                       ^

Swift.String.UTF16View.Index:2:24: note: candidate has non-matching type '(String.UTF16View.Index, String.UTF16View.Index) -> Bool'
    public static func ==(lhs: String.UTF16View.Index, rhs: String.UTF16View.Index) -> Bool
                       ^

Swift.String.UTF8View.Index:2:24: note: candidate has non-matching type '(String.UTF8View.Index, String.UTF8View.Index) -> Bool'
    public static func ==(lhs: String.UTF8View.Index, rhs: String.UTF8View.Index) -> Bool
                       ^

Swift.UnicodeDecodingResult:15:24: note: candidate has non-matching type '(UnicodeDecodingResult, UnicodeDecodingResult) -> Bool'
    public static func ==(lhs: UnicodeDecodingResult, rhs: UnicodeDecodingResult) -> Bool
                       ^

Swift.UnicodeScalar:2:24: note: candidate has non-matching type '(UnicodeScalar, UnicodeScalar) -> Bool'
    public static func ==(lhs: UnicodeScalar, rhs: UnicodeScalar) -> Bool
                       ^

Swift.UnsafeMutablePointer<Pointee>:2:24: note: candidate has non-matching type '<Pointee> (UnsafeMutablePointer<Pointee>, UnsafeMutablePointer<Pointee>) -> Bool'
    public static func ==(lhs: UnsafeMutablePointer<Pointee>, rhs: UnsafeMutablePointer<Pointee>) -> Bool
                       ^

Swift.UnsafePointer<Pointee>:2:24: note: candidate has non-matching type '<Pointee> (UnsafePointer<Pointee>, UnsafePointer<Pointee>) -> Bool'
    public static func ==(lhs: UnsafePointer<Pointee>, rhs: UnsafePointer<Pointee>) -> Bool
                       ^

Swift.UnsafeMutableRawPointer:4:24: note: candidate has non-matching type '(UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Bool'
    public static func ==(lhs: UnsafeMutableRawPointer, rhs: UnsafeMutableRawPointer) -> Bool
                       ^

Swift.UnsafeRawPointer:4:24: note: candidate has non-matching type '(UnsafeRawPointer, UnsafeRawPointer) -> Bool'
    public static func ==(lhs: UnsafeRawPointer, rhs: UnsafeRawPointer) -> Bool
                       ^

Swift._SwiftNSOperatingSystemVersion:2:24: note: candidate has non-matching type '(_SwiftNSOperatingSystemVersion, _SwiftNSOperatingSystemVersion) -> Bool'
    public static func ==(lhs: _SwiftNSOperatingSystemVersion, rhs: _SwiftNSOperatingSystemVersion) -> Bool
                       ^

Swift.AnyIndex:10:24: note: candidate has non-matching type '(AnyIndex, AnyIndex) -> Bool'
    public static func ==(lhs: AnyIndex, rhs: AnyIndex) -> Bool
                       ^

Swift.Mirror:95:34: note: candidate has non-matching type '(Mirror.DisplayStyle, Mirror.DisplayStyle) -> Bool'
        infix public static func ==(a: Mirror.DisplayStyle, b: Mirror.DisplayStyle) -> Bool
                                 ^

error: MyPlayground.playground:2:17: error: protocol 'Equatable' can only be used as a generic constraint because it has Self or associated type requirements
    struct Bar: Equatable {
                ^

@belkadan
Copy link
Contributor

belkadan commented Feb 6, 2017

@DougGregor, have we seen this before?

@DougGregor
Copy link
Member

Huh, that's lame. This should work.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2022
@AnthonyLatsis AnthonyLatsis added duplicate Resolution: Duplicates another issue type checker Area → compiler: Semantic analysis conformances Feature → protocol: protocol conformances operators Feature: operators unexpected error Bug: Unexpected error nested types Feature: nested types labels Feb 22, 2023
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. compiler The Swift compiler in itself conformances Feature → protocol: protocol conformances duplicate Resolution: Duplicates another issue nested types Feature: nested types operators Feature: operators type checker Area → compiler: Semantic analysis unexpected error Bug: Unexpected error
Projects
None yet
Development

No branches or pull requests

4 participants