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

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

cmd/compile: Wrong type reported for constant in type mismatch report #8409

btracey opened this issue Jul 22, 2014 · 4 comments
Milestone

Comments

@btracey
Copy link
Contributor

@btracey 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
Copy link
Member

@minux 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.

Loading

@btracey
Copy link
Contributor Author

@btracey 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

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 23, 2014

Comment 3:

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

Status changed to Accepted.

Loading

@btracey
Copy link
Contributor Author

@btracey 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

Loading

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: Wrong type reported for constant in type mismatch report 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
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants