# Can anyone explain the error message?

**URL:** <https://forums.swift.org/t/can-anyone-explain-the-error-message/71240>\
**Category:** Using Swift\
**Tags:** generics, structs\
**Created:** [April 13, 2024, 3:37pm UTC](https://forums.swift.org/t/can-anyone-explain-the-error-message/71240 "2024-04-13T15:37:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alc](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alc/32/33654_2.png) [@Alc](https://forums.swift.org/u/Alc)\
**Post date:** [April 13, 2024, 3:37pm UTC](https://forums.swift.org/t/can-anyone-explain-the-error-message/71240/1 "2024-04-13T15:37:15Z")

</div>

I understand that (in this code) I cannot compare generics that differ in types, but I do not understand the error message. Can anyone explain why it says it cannot compare "two `'Struct<String>'` operands" when one is a `String` and other is an `Int`? I would expect the error message to be something like this

Error message that is intuitive to me (with my current understanding)

```swift
error: binary operator '==' cannot be applied to 'Struct<String>' and 'Struct<Int>' operands

```

Actual error message

```swift
error: binary operator '==' cannot be applied to two 'Struct<String>' operands

```

Code

```swift
struct Struct<T: Equatable> {
    let val: T

    init(_ val: T) {
        self.val = val
    }

    static func == (lhs: Struct, rhs: Struct) -> Bool{
        lhs.val == rhs.val
    }
}

print(Struct(0) == Struct(0)) // true
// print(Struct("0") == Struct(0)) // error: binary operator '==' cannot be applied to two 'Struct<String>' operands

```

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [April 13, 2024, 4:39pm UTC](https://forums.swift.org/t/can-anyone-explain-the-error-message/71240/2 "2024-04-13T16:39:02Z")

</div>

Sounds like a compiler bug to me, not a deliberate message. Worth filing!

---

<div class="post-metadata">

**Author:** ![Alc](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/alc/32/33654_2.png) [@Alc](https://forums.swift.org/u/Alc)\
**Post date:** [April 14, 2024, 2:37am UTC](https://forums.swift.org/t/can-anyone-explain-the-error-message/71240/4 "2024-04-14T02:37:16Z")

</div>

Thank you for replying @jrose, I have created an issue.

> <https://github.com/apple/swift/issues/73029>
>
> \### Description
> 
> When the following code is run, the error I get is
> 
> \`\`\`
> erro…r: binary operator '==' cannot be applied to two 'MyStruct\<String\>' operands
> \`\`\`
> 
> While it is apparent that generics that differ in types cannot be compared, the error message does not indicate that is indeed the problem here. It says it cannot compare "two \`'MyStruct\<String\>'\` operands", however, one is a \`MyStruct\<String\>\` and other is a \`MyStruct\<Int\>\`.
> 
> \### Reproduction
> 
> \`\`\`swift
> struct MyStruct\<T: Equatable\> {
> let val: T
> 
> init(\_ val: T) {
> self.val = val
> }
> 
> static func == (lhs: MyStruct, rhs: MyStruct) -\> Bool{
> lhs.val == rhs.val
> }
> }
> 
> print(MyStruct(0) == MyStruct(0)) // true
> print(MyStruct("0") == MyStruct(0))
> \`\`\`
> 
> 
> \### Expected behavior
> 
> I would expect an intuitive error message like so, that shows what exactly is the problem (types are different)
> \`\`\`
> error: binary operator '==' cannot be applied to 'MyStruct\<String\>' and 'MyStruct\<Int\>' operands
> \`\`\`
> 
> \### 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
> 
> Asked this in \[Swift forums\](https://forums.swift.org/t/can-anyone-explain-the-error-message/71240) and I was suggested to file a report here.

PS: deleted the earlier message as I replied to my own question instead of yours 🙃 apologies for the double pings.
