Definitely yes. I just sent a message in another thread in this discussion
group

BR,
Roland

Quoting myself:

Obviously, even just calling a "methods" of some struct instance that is
not initialized succeeds in Go. A panic occurs only when the program tries
to derefer nil pointer:

'func (ev *Event) do()' only uses the pointer but does not derefer it.
Thus, no panic.

Here 'func (ev Event) do2()' derefers nil pointer already before call.
Panic in main.main()

https://go.dev/play/p/O_C0RpXb46h

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x47f812]

goroutine 1 [running]:
main.main()
        /tmp/sandbox1681946220/prog.go:14 +0x112


Here 'func (ev *Event) getS()' derefers the pointer. Panic happens inside
the main.getS()
https://go.dev/play/p/lto_JSFC2Qd

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x47f8d4]

goroutine 1 [running]:
main.(*Event).getS(0x4b2a40)
        /tmp/sandbox1571083836/prog.go:35 +0x14



Am Fr., 26. Nov. 2021 um 06:39 Uhr schrieb shinya sakae <
sakashin10291...@gmail.com>:

> Hi.
> I've been using Go for a while now, and I've noticed something.
> Do pointer receiver methods need to be checked for nil?
> In the standard package, it may or may not be checked.
> I'd like to hear your opinions.
>
> --
> 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/8bada92b-f179-4133-adcf-0cf971671b00n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/8bada92b-f179-4133-adcf-0cf971671b00n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CA%2B8p0G02gUnphuyLMnuYk6De7RHao77jxVOq0cOLtMM7WCDDZA%40mail.gmail.com.

Reply via email to