Source File
errsupport.go
Belonging Package
go/types
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.// Source: ../../cmd/compile/internal/types2/errsupport.go// Copyright 2024 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.// This file implements support functions for error messages.package types// lookupError returns a case-specific error when a lookup of selector sel in the// given type fails but an object with alternative spelling (case folding) is found.// If structLit is set, the error message is specifically for struct literal fields.func ( *Checker) ( Type, string, Object, bool) string {// Provide more detail if there is an unexported object, or one with different capitalization.// If selector and object are in the same package (==), export doesn't matter, otherwise (!=) it does.// Messages depend on whether it's a general lookup or a field lookup in a struct literal.//// case sel pkg have message (examples for general lookup)// ---------------------------------------------------------------------------------------------------------// ok x.Foo == Foo// misspelled x.Foo == FoO type X has no field or method Foo, but does have field FoO// misspelled x.Foo == foo type X has no field or method Foo, but does have field foo// misspelled x.Foo == foO type X has no field or method Foo, but does have field foO//// misspelled x.foo == Foo type X has no field or method foo, but does have field Foo// misspelled x.foo == FoO type X has no field or method foo, but does have field FoO// ok x.foo == foo// misspelled x.foo == foO type X has no field or method foo, but does have field foO//// ok x.Foo != Foo// misspelled x.Foo != FoO type X has no field or method Foo, but does have field FoO// unexported x.Foo != foo type X has no field or method Foo, but does have unexported field foo// missing x.Foo != foO type X has no field or method Foo//// misspelled x.foo != Foo type X has no field or method foo, but does have field Foo// missing x.foo != FoO type X has no field or method foo// inaccessible x.foo != foo cannot refer to unexported field foo// missing x.foo != foO type X has no field or method fooconst (= iota// no object found// found object with different spelling// found object with name differing only in first letter// found object with matching name but inaccessible from the current package)// determine case:=var string // alternative spelling of selector; if anyif != nil {= .Name()if .Pkg() == .pkg {assert( != ) // otherwise there is no lookup error=} else if isExported() {if isExported() {=} else if tail() == tail() {=}} else if isExported() {if tail() == tail() {=}} else if == {=}}if {switch {case :return .sprintf("unknown field %s in struct literal of type %s", , )case :return .sprintf("unknown field %s in struct literal of type %s, but does have %s", , , )case :return .sprintf("unknown field %s in struct literal of type %s, but does have unexported %s", , , )case :return .sprintf("cannot refer to unexported field %s in struct literal of type %s", , )}} else {:= "object"switch .(type) {case *Var:= "field"case *Func:= "method"}switch {case :return .sprintf("type %s has no field or method %s", , )case :return .sprintf("type %s has no field or method %s, but does have %s %s", , , , )case :return .sprintf("type %s has no field or method %s, but does have unexported %s %s", , , , )case :return .sprintf("cannot refer to unexported %s %s", , )}}panic("unreachable")}// tail returns the string s without its first (UTF-8) character.// If len(s) == 0, the result is s.func ( string) string {for , := range {if > 0 {return [:]}}return}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)