Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile, go/types2: for case sensitive mismatches in function/method/attribute lookups please suggest "but does have $<CASE_INSENSITIVE_EQUIVALENT>" #70549

Open
odeke-em opened this issue Nov 25, 2024 · 5 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@odeke-em
Copy link
Member

Go version

go version devel go1.24-2b33434287 Fri Nov 8 01:06:04 2024 +0000 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='/home/emmanuel/go/src/go.googlesource.com/go/bin'
GOCACHE='/home/emmanuel/.cache/go-build'
GOENV='/home/emmanuel/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/emmanuel/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/emmanuel/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/emmanuel/go/src/go.googlesource.com/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/emmanuel/go/src/go.googlesource.com/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.24-2b33434287 Fri Nov 8 01:06:04 2024 +0000'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/emmanuel/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/emmanuel/go/src/github.com/googleapis/google-cloud-go/spanner/go.mod'
GOWORK='/home/emmanuel/go/src/github.com/googleapis/google-cloud-go/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build825742400=/tmp/go-build -gno-record-gcc-switches'

What did you do?

While working on some terse library with a ton of symbols/functions, in which the nomenclature for a bunch of symbols at times defies expectations in case, I had such code

// Add a unaryClientInterceptor and streamClientInterceptor.
        reqIDInjector := new(requestIDHeaderInjector)
        opts = append(opts,
            option.WithGRPCDialOption(grpc.WithchainStreamInterceptor(reqIDInjector.interceptStream)),
            option.WithGRPCDialOption(grpc.WithchainUnaryInterceptor(reqIDInjector.interceptUnary)),
        )

to reference https://pkg.go.dev/google.golang.org/grpc#WithChainStreamInterceptor and https://pkg.go.dev/google.golang.org/grpc#WithChainUnaryInterceptor

What did you see happen?

$ go test -run=TestRequestID
# cloud.google.com/go/spanner [cloud.google.com/go/spanner.test]
./client.go:414:35: undefined: grpc.WithchainStreamInterceptor
./client.go:415:35: undefined: grpc.WithchainUnaryInterceptor
FAIL	cloud.google.com/go/spanner [build failed]

What did you expect to see?

$ go test -run=TestRequestID
# cloud.google.com/go/spanner [cloud.google.com/go/spanner.test]
./client.go:414:35: undefined: grpc.WithchainStreamInterceptor, did you mean "grpc.WithChainStreamInterceptor"?
./client.go:415:35: undefined: grpc.WithchainUnaryInterceptor, did you mean "grpc.WithChainUnaryInterceptor"?
FAIL	cloud.google.com/go/spanner [build failed]

If there is a case insensitve mismatch, kindly please suggest the first one so that the user can trivially fix their code instead of
having to eye-ball to figure out their typo.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 25, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/631356 mentions this issue: cmd/compile, go/types: suggest for case-insensitive matches on undefined symbols

@GoVeronicaGo
Copy link

CC: @golang/compiler

@GoVeronicaGo GoVeronicaGo added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 25, 2024
@timothy-king
Copy link
Contributor

Thanks. This is a plausible usability improvement for the compiler.

If we open this door, it would be nice to try to identify a good enough and helpful subset once. It seems like a lot of details need to be ironed out.

  • What about near misspellings of function names? How near?
  • What about near misses to unexported symbols? Different error message?
  • What about near matches for package names?
  • What about near matches for variable names that could select a method?
  • What about 2 or more near matches? What is the error message then? What is the priority between them?

cc @griesemer

@ianlancetaylor
Copy link
Member

Note that we already do matches if the case of the first letter differs.

	fmt.Println(bytes.NewReader(nil).len())
foo.go:9:35: bytes.NewReader(nil).len undefined (type *bytes.Reader has no field or method len, but does have method Len)

@griesemer griesemer added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 25, 2024
@griesemer griesemer added this to the Go1.25 milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
Development

No branches or pull requests

7 participants