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: Compile error message is not accurate #23532

Closed
ysqi opened this issue Jan 24, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@ysqi
Copy link

commented Jan 24, 2018

Please answer these questions before submitting your issue. Thanks!

What did you do?

error message is not accurate after writen error code:

package main

import "fmt"

func main() {

	callback2(func(v int, m *msg) {
		fmt.Println("got")
	})

}

type msg struct {
}

func callback2(cb func(int, m *msg)) {     // <----here : extra  `m` 
	callback(cb) 
}

func callback(cb func(int, *msg)) {
	cb(1, &msg{})
}

What did you expect to see?

notify extra m

What did you see instead?

./err.go:7:12: cannot use func literal (type func(int, *msg)) as type func(*msg, *msg) in argument to callback2
./err.go:17:11: cannot use cb (type func(*msg, *msg)) as type func(int, *msg) in argument to callback

System details

go version go1.9.2 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/user/Documents/dev/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hd/qg8xbds12bs0x4rqzgx6ggwc0000gn/T/go-build720067211=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOROOT/bin/go version: go version go1.9.2 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9.2
uname -v: Darwin Kernel Version 17.3.0: Thu Nov  9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.2
BuildVersion:	17C88
lldb --version: lldb-900.0.64
  Swift-4.0
@mvdan

This comment has been minimized.

Copy link
Member

commented Jan 24, 2018

The reason is because func(int, m *msg) is interpreted as func(int *msg, m *msg). That is, just like one can do func(a, b, c, d int) to receive four integers.

Perhaps the confusion here comes from the fact that int is simply a builtin type. You can call your variables and parameters int if you wish. With that in mind, the compiler can not help you with a better error message, because you have given it a valid program, syntactically speaking.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 24, 2018

Working as expected. Closing. Always open for suggestions for better error messages, though.

@ysqi

This comment has been minimized.

Copy link
Author

commented Jan 25, 2018

@mvdan thank you a lot.

@mikioh mikioh changed the title Compile error message is not accurate cmd/compile: Compile error message is not accurate Jan 26, 2018

@golang golang locked and limited conversation to collaborators Jan 26, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.