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

go/types: fix implementation of assignability check #54424

Closed
griesemer opened this issue Aug 12, 2022 · 3 comments
Closed

go/types: fix implementation of assignability check #54424

griesemer opened this issue Aug 12, 2022 · 3 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@griesemer
Copy link
Contributor

griesemer commented Aug 12, 2022

[edited]

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.

This appears to be just a bug in the assignment check.

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
@griesemer griesemer added the early-in-cycle A change that should be done early in the 3 month dev cycle. label Nov 15, 2022
@griesemer griesemer modified the milestones: Go1.20, Go1.21 Nov 15, 2022
@gopherbot
Copy link

This issue is currently labeled as early-in-cycle for Go 1.21.
That time is now, so a friendly reminder to look at it again.

@gopherbot
Copy link

Change https://go.dev/cl/498400 mentions this issue: go/types, types2: fix incorrect logic in assignability check

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed Thinking early-in-cycle A change that should be done early in the 3 month dev cycle. labels May 31, 2023
@griesemer
Copy link
Contributor Author

Marking a release blocker as this really needs to be fixed.

@griesemer griesemer changed the title spec: revisit assignment rules for type parameters go/types: fix implementation of assignability check Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants