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

dev.go2go: generic embedded field names are not found in composite literals #44345

Closed
griesemer opened this issue Feb 17, 2021 · 5 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

Example:

package main

type E[T any] struct {
	A T
}

type T struct {
	E[int]
}

func main() {
	_ = T{E[int]{A: 1}}
	//_ = T{E: E[int]{A: 1}} // <<< this should work

	// manually it does work:
	var x T
	x.E = E[int]{A: 1}
}

We get an error:

./prog.go2:13: unknown field 'E' in struct literal of type T

yet when a T is set up manually, the E field is recognized.

@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label Feb 17, 2021
@griesemer griesemer added this to the Go1.17 milestone Feb 17, 2021
@griesemer griesemer self-assigned this Feb 17, 2021
@griesemer
Copy link
Contributor Author

cc: @findleyr

@griesemer griesemer changed the title cmd/compile/internal/types2: generic embedded field names are not found in composite literals dev.go2go: generic embedded field names are not found in composite literals Feb 17, 2021
@griesemer
Copy link
Contributor Author

It appears this error message is coming from the compiler, not the type checker (both types2 and go/types can typecheck this code w/o problems). That is, the bug is probably in go/go2go in the dev.go2go branch. Unlikely that we're going to spend time to fix this in the prototype since we're now working on a real implementation (which will eventually appear in the playground).

@griesemer
Copy link
Contributor Author

Leaving for @ianlancetaylor to decide.

@ianlancetaylor
Copy link
Member

I agree that _ = T{E: E[int]{A: 1}} should work.

The go2go translation tool has many bugs with embedded fields.

@griesemer
Copy link
Contributor Author

This appears to be working fine in Go 1.18 (playground). 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

3 participants