5 ms·
Go does not have compile-time null safety or sum types :) foo := Foo{"hello"} fooPointer := &foo fooPointer = nil fmt.Println(fooPointer.Bar)
by kinjba11 4y ago
Go does not have compile-time null safety or sum types :)
foo := Foo{"hello"}
fooPointer := &foo
fooPointer = nil
fmt.Println(fooPointer.Bar)
> panic: runtime error: invalid memory address or nil pointer dereference
In a language like Kotlin a compile time error would prevent `fooPointer.Bar`, and in Rust `nil` does not exist. Go also does not have sum types, see for instance https://making.pusher.com/alternatives-to-sum-types-in-go/ https://making.pusher.com/alternatives-to-sum-types-in-go/