Skip to content

spec: comments on Selector example unclear #49141

@jpadrianoGo

Description

@jpadrianoGo

What version of Go are you using (go version)?

$ go version
The playground uses the latest stable release of Go.
The current version is go1.17.2.

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

https://golang.org/ref/spec#Selectors
I tried the Selector example.

I ran the Selector example from Go playground.
https://play.golang.org/p/_kaX9_8vKez

func main() {
	var t T2
	var p *T2

	fmt.Println(t.T0) // with t.T0 != nil (should be t.T0 == nil)
	fmt.Println(p)    // with p != nil (should be p == nil)
	//fmt.Println((*p).T0) // (*p).T0 != nil  (illegal invalid memory address or nil pointer dereference)
}

What did you expect to see?

type T0 struct {
	x int
}

func (*T0) M0()

type T1 struct {
	y int
}

func (T1) M1()

type T2 struct {
	z int
	T1
	*T0
}

func (*T2) M2()

type Q *T2

var t T2     // with t.T0 != nil
var p *T2    // with p != nil and (*p).T0 != nil

func main() {
	var t T2
	var p *T2

	fmt.Println(t.T0) // with t.T0 != nil (I expected t.T0 != nil but got nil)
	fmt.Println(p)    // with p != nil (I expected p != nil but got nil)
	//fmt.Println((*p).T0) // (*p).T0 != nil  (I expected (*p).T0 != nil  but got illegal invalid memory address or nil pointer dereference)
}

What did you see instead?

type T0 struct {
	x int
}

func (*T0) M0()

type T1 struct {
	y int
}

func (T1) M1()

type T2 struct {
	z int
	T1
	*T0
}

func (*T2) M2()

type Q *T2

var t T2     // with t.T0 == nil
var p *T2    // with p == nil and (*p).T0 == nil
func main() {
	var t T2
	var p *T2

	fmt.Println(t.T0) // with t.T0 != nil (should be t.T0 == nil)
	fmt.Println(p)    // with p != nil (should be p == nil)
	//fmt.Println((*p).T0) // (*p).T0 != nil  (illegal invalid memory address or nil pointer dereference)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions