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: confusing type checking error #14948

Closed
aclements opened this issue Mar 24, 2016 · 3 comments
Closed

cmd/compile: confusing type checking error #14948

aclements opened this issue Mar 24, 2016 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@aclements
Copy link
Member

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version go1.6 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    linux/amd64
  3. What did you do?
    http://play.golang.org/p/_P4s_RvFbr

This program mistakenly defines a function called "color" that returns a "color.Color". The intent was for the return type to refer to the "image/color" package, but of course the name was shadowed by the function itself.

  1. What did you expect to see?
    A non-confusing error message perhaps explaining that "color" is a function or perhaps that "color" refers to itself.
  2. What did you see instead?
prog.go:9: typechecking loop involving color
    prog.go:9 color.Color
    prog.go:9 <T>
    prog.go:9 color
    prog.go:9 <node DCLFUNC>

While technically correct, this error message reads like an internal failure of the type checker, especially since it's outputting internal compiler node names and gives no details about what lines 2 through 5 mean.

/cc @griesemer

@griesemer
Copy link
Contributor

For the reference: gotype complains with

$ gotype x.go
x.go:9:14: invalid operation: color (value of type func()) has no field or method Color

@griesemer griesemer self-assigned this Mar 24, 2016
@ianlancetaylor
Copy link
Contributor

gccgo says

foo.go:9:19: error: expected package
 func color() color.Color {
                   ^

@bradfitz bradfitz added this to the Unplanned milestone Apr 9, 2016
@ALTree ALTree added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 22, 2018
@griesemer
Copy link
Contributor

With Go 1.18 we now get the go/types (types2) error:

./prog.go:9:20: color.Color undefined (type func() has no field or method Color)

which seems pretty good. Closing.

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants