aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/types2/object.go49
-rw-r--r--src/cmd/compile/internal/types2/typexpr.go3
2 files changed, 51 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/types2/object.go b/src/cmd/compile/internal/types2/object.go
index dd2d415790..5d284ee61b 100644
--- a/src/cmd/compile/internal/types2/object.go
+++ b/src/cmd/compile/internal/types2/object.go
@@ -671,3 +671,52 @@ func writeFuncName(buf *bytes.Buffer, f *Func, qf Qualifier) {
}
buf.WriteString(f.name)
}
+
+// objectKind returns a description of the object's kind.
+func objectKind(obj Object) string {
+ switch obj := obj.(type) {
+ case *PkgName:
+ return "package name"
+ case *Const:
+ return "constant"
+ case *TypeName:
+ if obj.IsAlias() {
+ return "type alias"
+ } else if _, ok := obj.Type().(*TypeParam); ok {
+ return "type parameter"
+ } else {
+ return "defined type"
+ }
+ case *Var:
+ switch obj.Kind() {
+ case PackageVar:
+ return "package-level variable"
+ case LocalVar:
+ return "local variable"
+ case RecvVar:
+ return "receiver"
+ case ParamVar:
+ return "parameter"
+ case ResultVar:
+ return "result variable"
+ case FieldVar:
+ return "struct field"
+ }
+ case *Func:
+ if obj.Signature().Recv() != nil {
+ return "method"
+ } else {
+ return "function"
+ }
+ case *Label:
+ return "label"
+ case *Builtin:
+ return "built-in function"
+ case *Nil:
+ return "untyped nil"
+ }
+ if debug {
+ panic(fmt.Sprintf("unknown symbol (%T)", obj))
+ }
+ return "unknown symbol"
+}
diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go
index a79b54eacc..7d5932eec1 100644
--- a/src/cmd/compile/internal/types2/typexpr.go
+++ b/src/cmd/compile/internal/types2/typexpr.go
@@ -50,7 +50,8 @@ func (check *Checker) ident(x *operand, e *syntax.Name, wantType bool) {
// (see go.dev/issue/65344).
_, gotType := obj.(*TypeName)
if !gotType && wantType {
- check.errorf(e, NotAType, "%s is not a type", obj.Name())
+ check.errorf(e, NotAType, "%s (%s) is not a type", obj.Name(), objectKind(obj))
+
// avoid "declared but not used" errors
// (don't use Checker.use - we don't want to evaluate too much)
if v, _ := obj.(*Var); v != nil && v.pkg == check.pkg /* see Checker.use1 */ {