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: Wrong type reported for constant in type mismatch report #8409

Open
btracey opened this Issue Jul 22, 2014 · 4 comments

Comments

Projects
None yet
4 participants
@btracey
Contributor

btracey commented Jul 22, 2014

In the following code:

func Foo() []float64 {
    return 0
}

gc reports "cannot use 0 (type int) as type []float64 in return argument".
However, 0 is not an integer, 0 is a constant.

http://play.golang.org/p/hyUix7H8aX
@minux

This comment has been minimized.

Member

minux commented Jul 22, 2014

Comment 1:

you can't actually return a untyped constant "type" from a function,
so 0 here must be treated as some type, as the context doesn't specify
which integer type to use, it defaults to int.

Status changed to WorkingAsIntended.

@btracey

This comment has been minimized.

Contributor

btracey commented Jul 22, 2014

Comment 2:

I agree one cannot return an untyped constant from a function, but one can "use" the
untyped constant 0 in many ways. For example, the following code is correct
func Foo() float64 {
    return 0
}
Here, 0 is used as a float64, not as an int. Thus, it seems like the error message
should be 
"cannot use 0 (untyped constant literal) as type []float64 in return argument"
One may never use an int as a float64, but one may use an untyped constant literal as a
float64
@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Jul 23, 2014

Comment 3:

Labels changed: added repo-main, release-none.

Status changed to Accepted.

@btracey

This comment has been minimized.

Contributor

btracey commented Oct 24, 2014

Comment 4:

Here is another example of the same problem but in a different context
http://play.golang.org/p/2YtAt2ZXvX

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed release-none labels Apr 10, 2015

@rsc rsc changed the title from cmd/gc: Wrong type reported for constant in type mismatch report to cmd/compile: Wrong type reported for constant in type mismatch report Jun 8, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment