Skip to content

spec: clarify the semantics of &p.Field when p is nil #4238

@mirtchovski

Description

@mirtchovski
Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
http://golang.org/doc/devel/release.html  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1. http://play.golang.org/p/Bh8FhRu7NQ
2. click 'run'
3. corollary: http://play.golang.org/p/ytggyD6PGV

What is the expected output?
According to the spec, section "selectors", point 4: "If x is of pointer
or interface type and has the value nil, assigning to, evaluating, or calling x.f causes
a run-time panic."

What do you see instead?
The first call to a nil pointer allows the method on "s" to be called. The
second however panics. The difference between the two structs is one byte.

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g and the playground.

Which operating system are you using?
Linux, OSX, Playground

Which version are you using?  (run 'go version')
go version devel +cfa9208b98fc Fri Oct 12 23:19:39 2012 +0800

Please provide any additional information below.
Initially the issue was experienced by real users getting confusing errors deep inside
mutex.Lock while trying to log to a nil logger.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions