[]byte is a no comparable type.

quoting the docs:




*comparable is an interface that is implemented by all comparable 
types(booleans, numbers, strings, pointers, channels, interfaces,arrays of 
comparable types, structs whose fields are all comparable types).The 
comparable interface may only be used as a type parameter constraint,not as 
the type of a variable.*

for comparing bytes, use the "bytes" package.

here is an example from yours
https://go.dev/play/p/6PBnbGw-rVo?v=gotip

On Wednesday, December 15, 2021 at 5:39:39 PM UTC+1 Johannes Kohnen wrote:

> Hello folks, 
>
> I've stumbled over a thing and I don't understand if what I've found is 
> intentionally possible by design...
>
> https://go.dev/play/p/SIxOV1FnTzX?v=gotip 
>
> Why can I compare int with == when it was instantiated from the "any" type 
> parameter? 
>
> The origin of my question is my implementation of a left right map which 
> I've ported to generics.  While doing so I've uncovered a couple bugs in 
> Jetbrains GoLand and reported them.  Except this one, because I've 
> overlooked it and I now am confused:
>
>
> https://github.com/jwkohnen/lrmap/blob/a6b9a6715069a7ad24de7cf84fe949dd7f194c0a/lrmap_test.go#L26
>
> In this line I compare two int values with !=, and this code compiles. 
> Though, those value types were instantiated from the "any" type 
> constraint.  GoLand reports an error in that line "Invalid operation: _v != 
> v (the operator != is not defined on V)".
>
> From my reading of the generics proposal GoLand is right, but the compiler 
> says otherwise.  How exactly are the operations that are defined on an 
> "any" type inferred?
>
> Sorry if the answer is right there in the proposal; my reading 
> comprehension fluctuates wildly these days. 
>
> Cheers,
> Johannes
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f0920648-a47a-45a6-8ab4-8943273efa54n%40googlegroups.com.

Reply via email to