mirror of
https://github.com/golang/go
synced 2024-11-22 15:04:52 -07:00
e6c973198d
ODOTMETH is unique among SelectorExpr expressions, in that Sel gets mangled so that it no longer has the original identifier that was selected (e.g., just "Foo"), but instead the qualified symbol name for the selected method (e.g., "pkg.Type.Foo"). This is rarely useful, and instead results in a lot of compiler code needing to worry about undoing this change. This CL changes ODOTMETH to leave the original symbol in place. The handful of code locations where the mangled symbol name is actually wanted are updated to use ir.MethodExprName(n).Sym() or (equivalently) ir.MethodExprName(n).Func.Sym() instead. Historically, the compiler backend has mistakenly used types.Syms where it should have used ir.Name/ir.Funcs. And this change in particular may risk breaking something, as the SelectorExpr.Sel will no longer point at a symbol that uniquely identifies the called method. However, I expect CL 280294 (desugar OCALLMETH into OCALLFUNC) to have substantially reduced this risk, as ODOTMETH expressions are now replaced entirely earlier in the compiler. Passes toolstash -cmp. Change-Id: If3c9c3b7df78ea969f135840574cf89e1d263876 Reviewed-on: https://go-review.googlesource.com/c/go/+/280436 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
43 lines
2.7 KiB
Go
43 lines
2.7 KiB
Go
// errorcheck
|
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package p
|
|
|
|
import "./f1"
|
|
|
|
func main() {
|
|
f := f1.Foo{
|
|
doneChan: nil, // ERROR "cannot refer to unexported field 'doneChan' in struct literal of type f1.Foo"
|
|
DoneChan: nil, // ERROR "unknown field 'DoneChan' in struct literal of type f1.Foo"
|
|
Name: "hey",
|
|
name: "there", // ERROR "unknown field 'name' in struct literal of type f1.Foo .but does have Name."
|
|
noSuchPrivate: true, // ERROR "unknown field 'noSuchPrivate' in struct literal of type f1.Foo"
|
|
NoSuchPublic: true, // ERROR "unknown field 'NoSuchPublic' in struct literal of type f1.Foo"
|
|
foo: true, // ERROR "unknown field 'foo' in struct literal of type f1.Foo"
|
|
hook: func() {}, // ERROR "cannot refer to unexported field 'hook' in struct literal of type f1.Foo"
|
|
unexported: func() {}, // ERROR "unknown field 'unexported' in struct literal of type f1.Foo"
|
|
Exported: func() {}, // ERROR "unknown field 'Exported' in struct literal of type f1.Foo"
|
|
}
|
|
f.doneChan = nil // ERROR "f.doneChan undefined .cannot refer to unexported field or method doneChan."
|
|
f.DoneChan = nil // ERROR "f.DoneChan undefined .type f1.Foo has no field or method DoneChan."
|
|
f.name = nil // ERROR "f.name undefined .type f1.Foo has no field or method name, but does have Name."
|
|
|
|
_ = f.doneChan // ERROR "f.doneChan undefined .cannot refer to unexported field or method doneChan."
|
|
_ = f.DoneChan // ERROR "f.DoneChan undefined .type f1.Foo has no field or method DoneChan."
|
|
_ = f.Name
|
|
_ = f.name // ERROR "f.name undefined .type f1.Foo has no field or method name, but does have Name."
|
|
_ = f.noSuchPrivate // ERROR "f.noSuchPrivate undefined .type f1.Foo has no field or method noSuchPrivate."
|
|
_ = f.NoSuchPublic // ERROR "f.NoSuchPublic undefined .type f1.Foo has no field or method NoSuchPublic."
|
|
_ = f.foo // ERROR "f.foo undefined .type f1.Foo has no field or method foo."
|
|
_ = f.Exported
|
|
_ = f.exported // ERROR "f.exported undefined .type f1.Foo has no field or method exported, but does have Exported."
|
|
_ = f.Unexported // ERROR "f.Unexported undefined .type f1.Foo has no field or method Unexported."
|
|
_ = f.unexported // ERROR "f.unexported undefined .cannot refer to unexported field or method unexported."
|
|
f.unexported = 10 // ERROR "f.unexported undefined .cannot refer to unexported field or method unexported."
|
|
f.unexported() // ERROR "f.unexported undefined .cannot refer to unexported field or method unexported."
|
|
_ = f.hook // ERROR "f.hook undefined .cannot refer to unexported field or method hook."
|
|
}
|