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

Comments

Projects
None yet
4 participants
@mvdan
Copy link
Member

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 label Oct 18, 2018

@griesemer griesemer added NeedsFix and removed NeedsDecision 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

This comment has been minimized.

Copy link
Contributor

commented Oct 18, 2018

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

@gopherbot

This comment has been minimized.

Copy link

commented Oct 23, 2018

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

@mdempsky

This comment has been minimized.

Copy link
Member

commented Oct 24, 2018

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.

@gopherbot gopherbot closed this in 6761b1e Oct 24, 2018

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