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/go2go: spurious compile error when accessing field promoted from parameterized type embedded in struct #44689

Closed
adonovan opened this issue Feb 28, 2021 · 5 comments

Comments

@adonovan
Copy link

@adonovan adonovan commented Feb 28, 2021

This program (https://go2goplay.golang.org/p/qrOFrB-Udhh):

type P[V any] struct{ v V }
type Q struct{ P[int64] }

func _(q *Q) {
	_ = q.P   // ok
	_ = q.P.v // ok
	_ = q.v   // compile error: q.P undefined (type *Q has no field or method P)
}

causes go2go to emit the spurious-looking error shown in the comment.

(The error message is also confusing because the q.P field access doesn't appear on the source line.)

(Similar but different: #44688)

dev.go2go version 356c171

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 28, 2021

This one is just a bug in the experimental go2go tool (the distinction is that it doesn't say "type checking failed for ..."). The go2go tool has many bugs involving embedded fields. I'm willing to review patches to fix it, but I don't plan to do further work on it myself.

@adonovan
Copy link
Author

@adonovan adonovan commented Feb 28, 2021

(the distinction is that it doesn't say "type checking failed for ...").

I'm confused. Shouldn't this be a legal program?

The go2go tool has many bugs involving embedded fields

Russ invited me to try out the generics implementation on some realistic programs, and these two issues were both obstacles for the programs I wanted to write. Should I be using something other than go2go?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 1, 2021

What I mean is: if you get an error message "type checking failed for..." for a valid program, then there is a bug in the type checker, and that bug needs to be fixed.

If you get an error for a valid program that does not say "type checking failed for...", then you have encountered a bug in the experimental go2go tool. The tool was intended for experimenting with generics while the proposal was being shaped, and we're beyond that point now. The tool has many limitations and I have no plans to continue enhancing it. I think it's more important to work on the actual implementation of generics.

Russ invited me to try out the generics implementation on some realistic programs, and these two issues were both obstacles for the programs I wanted to write. Should I be using something other than go2go?

No, there is nothing else. But avoid embedded fields involving generic types. Support for them is limited. The only way that a tool like go2go can support them is to completely rewrite all field references. It could do that in principle, but it's a fair amount of work, and it was never done.

Sorry.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jun 7, 2021

I think this is a dup of #43621?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 7, 2021

We aren't going to do anything in any case, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants