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

Open
griesemer opened this issue Feb 17, 2021 · 4 comments
Open
Assignees
Labels
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Feb 17, 2021

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 this to the Go1.17 milestone Feb 17, 2021
@griesemer griesemer self-assigned this Feb 17, 2021
@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Feb 17, 2021

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

@griesemer griesemer commented Feb 17, 2021

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

@griesemer griesemer commented Feb 17, 2021

Leaving for @ianlancetaylor to decide.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 18, 2021

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

The go2go translation tool has many bugs with embedded fields.

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

Successfully merging a pull request may close this issue.

None yet
2 participants