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

spec: revisit assignment rules for type parameters #54424

Open
griesemer opened this issue Aug 12, 2022 · 0 comments
Open

spec: revisit assignment rules for type parameters #54424

griesemer opened this issue Aug 12, 2022 · 0 comments
Assignees
Labels
Milestone

Comments

@griesemer
Copy link
Contributor

griesemer commented Aug 12, 2022

func f[P ~*T, T any]() {
	var p P
	var tp *T
	tp = p // <<< ERROR HERE
}

is currently not permitted:

cannot use p (variable of type P constrained by ~*T) as type *T in assignment:
	P does not implement *T (type *T is pointer to interface, not interface)

because type parameters are following the rules for interfaces in this assignment (their constraints are interfaces). This ties in with the question of what the underlying type of a type parameter is (currently it's the constraint interface); the rest follows from that.

This may not be the right approach for type parameters; or at least not the most user-friendly approach.

cc: @rsc (who raised the issue)
cc: @findleyr @ianlancetaylor

@griesemer griesemer added this to the Go1.20 milestone Aug 12, 2022
@griesemer griesemer self-assigned this Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant