Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self-embedded struct allows to dereference nil #49

Open
cosmos72 opened this issue May 12, 2018 · 1 comment
Open

self-embedded struct allows to dereference nil #49

cosmos72 opened this issue May 12, 2018 · 1 comment

Comments

@cosmos72
Copy link

cosmos72 commented May 12, 2018

Another allegedly contrived - but valid - use of self-referencing types. After declaring

import "fmt"
type X struct { *X }
var x X

the call fmt.Println(x.X) should print nil - instead it prints [] - a very minor issue.

The real issue is that

fmt.Println(x.X.X)

should panic due to nil pointer dereference - instead it succeeds and prints <nil>

Go playground behaviour is to print <nil> then panic: https://play.golang.org/p/n04z_sZemno

@glycerine
Copy link
Contributor

Thanks @cosmos72 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants