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: shouldn't report argument mismatch errors for using unexported functions #57489

Open
ross-spencer opened this issue Dec 28, 2022 · 2 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ross-spencer
Copy link

What version of Go are you using (go version)?

$ go version go1.19.4 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ross-spencer/.cache/go-build"
GOENV="/home/ross-spencer/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ross-spencer/git/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ross-spencer/git/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3868854645=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"
	"path/filepath"
)

func main() {
	fmt.Println("Hello, 世界")
	arr := []string{"dir", "path"}
	fmt.Println("arr")
	fmt.Println(filepath.join("a", "b"))
}

What did you expect to see?

Accidentally called .join (lower-case 'j') and expected an error, instead I am told I can supply a string array to the function.

What did you see instead?

./test.go:12:2: arr declared but not used
./test.go:14:23: join not exported by package filepath
./test.go:14:33: too many arguments in call to filepath.join
	have (string, string)
	want ([]string)
@seankhliao seankhliao changed the title filepath: join() (lower-case 'j') is showing as an exported/undocumented function cmd/compile: shouldn't report argument mismatch errors for using unexported functions Dec 28, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 28, 2022
@seankhliao
Copy link
Member

note there is the unexported error too:

./test.go:14:23: join not exported by package filepath

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Documentation labels Dec 28, 2022
@mknyszek mknyszek added this to the Backlog milestone Dec 28, 2022
@griesemer
Copy link
Contributor

griesemer commented Dec 28, 2022

Simplified:

package main
import "path/filepath"
var _ = filepath.join("a", "b")

produces

$ go run x.go
# command-line-arguments
./x.go:3:18: join not exported by package filepath
./x.go:3:28: too many arguments in call to filepath.join
	have (string, string)
	want ([]string)

Ideally, the 2nd error shouldn't be reported. Type-checker issue.

@griesemer griesemer self-assigned this Dec 28, 2022
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

5 participants