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 "cannot call non-function" error when a field is ambiguous #28268

Closed
mvdan opened this issue Oct 18, 2018 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Oct 18, 2018

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

go version devel +8ccafb1ac7 Thu Oct 18 04:57:41 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes - play link below.

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

Reproduces on the playground.

What did you do?

https://play.golang.org/p/vwhrdByyhFi

What did you expect to see?

prog.go:7:6: type T has both field and method named F

What did you see instead?

prog.go:7:6: type T has both field and method named F
prog.go:11:13: cannot call non-function t.F (type int)

I had this in a real program where there were many calls to t.F. Thus, half my screen was filled with that error, and I was very confused. It wasn't until I scrolled up and saw the first error that I realised what was going on.

I think the second error is redundant and confusing. t.F is ambiguous, so it's neither a func nor an integer. I think we should mark the field type as broken, and not report any errors because of its type.

A less invasive change would be to drop the (type int) or change it with (ambiguous type), but I'd prefer if we dropped the error altogether.

/cc @griesemer @odeke-em @mdempsky

@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 18, 2018
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 18, 2018
@griesemer griesemer self-assigned this Oct 18, 2018
@griesemer griesemer added this to the Go1.12 milestone Oct 18, 2018
@griesemer
Copy link
Contributor

Marking for 1.12 if we get to it but not urgent.

@gopherbot
Copy link

Change https://golang.org/cl/144259 mentions this issue: cmd/compile: better errors for structs with conflicting fields and methods

@mdempsky
Copy link
Member

My 2c: I think the fix here is to just suppress the errors at t.F's use. We should emit errors where users can fix errors, and there's nothing to be done at the use sites to fix a duplicate field/method declaration error: those need to be fixed at one of the declaration sites, which we're already emitting errors at.

Ambiguous selector errors are emitted at the selection site because they can be fixed there by further qualifying which (valid) selectable was intended. Whereas in this case, defining two fields/methods on the same type is invalid.

@golang golang locked and limited conversation to collaborators Oct 24, 2019
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

4 participants