3
groxx
17d

Golang you guys. Because in a lang where you can't override == behavior, obviously == can panic.

type s struct{ f func() }
x := s{}
y := s{}
x == y // panics
x == x // even this panics

Comments
  • 1
    What the fuck are you talking about?
    The compiler simply blocks that stuff.
    Nothing panics here.
  • 4
    @metamourge it allows struct compare, but forbids any non-trivial structures like the one in rant with func type. It’s basically just lack of generics.

    If you really need to compare full structure then reflection can be used (reflect.DeepEqual or sth like that), in other cases just write your own function, I doubt golang will ever allow to override operators for better..
  • 1
    @metamourge nope. Runtime panic. Try it out.
  • 1
    Holy shit that's retarded
  • 0
    Whoops, nope, I forgot the interface boxing. Sorry about that: https://play.golang.org/p/...

    @highlight
    type s struct{ f func() }
    var x, y interface{}
    x = s{}
    y = s{}
    _ = x == y
    // _ = x == x
  • 1
  • 1
    @groxx interface doesn’t change anything, change func() type to string and it will work
  • 1
    @SevenDeadlyBugs sure, but now it compiles and runs. Before / as originally posted it's a compile-time error
  • 1
    @groxx makes sense, you use empty interface which removes static typing and thus removes benefits of compile time errors.

    Create an non-empty interface with the same signature (but in method ofc), and you will get compile time error again. Empty interfaces are special case in golang, which allows to have value of any type in it, but then you need to parse it yourself by using reflection.
  • 0
    This works
    https://play.golang.org/p/...
    @highlight
    package main

    import (
    "fmt"
    )

    type s struct {
    }

    func (d *s) f() {
    fmt.Println("ok")
    }

    func main() {
    fmt.Println("Hello, playground")

    var x, y interface{}
    x = s{}
    y = s{}
    if x == y {
    fmt.Println("x == y")
    }
    if x == x {
    fmt.Println("x == x")
    }
    }
  • 0
Add Comment