-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/compile: adjustment needed for conversion rules for pointer conversions (?) #50815
Comments
I think this should work. It does in the non-generic equivalent. |
Based on @randall77's comment, tentatively marking as a release blocker. Maybe this is |
This is working as intended per the current rules and unrelated to structural types. Not a release blocker. |
We have special rules for generic conversions, but what we have here is not a generic conversion (at the top level). We convert a
Here This case has come up before, and maybe we need a new rule for this case (resp. an adjustment of the new rules added for generic conversions.) Leaving open for decision. |
I think we should probably permit this, but perhaps not for 1.18. |
It looks this pointer conversion rule for type parameters is more relaxed than ordinary types. package main
type Age int
func foo[T ~*Age](x T) *int {
return (*int)(x) // okay
}
type AgePtr *Age
//func bar(x AgePtr) *int {
// return (*int)(x) // error: cannot convert x (variable of type AgePtr) to type *int
//}
func main() {
var x AgePtr
var _ = foo[AgePtr](x)
} |
The following function also doesn't compile. func mud[T AgePtr](x T) *int {
return (*int)(x) // error
} So it looks the conversion rule in spec is not very accurate (or the
|
Too late for 1.20. |
This issue is currently labeled as early-in-cycle for Go 1.21. |
Too late for 1.21. |
This issue is currently labeled as early-in-cycle for Go 1.22. |
Reconsider this also in light of #63940. |
This issue is currently labeled as early-in-cycle for Go 1.23. |
See also #63940 which may impact this one way or another. |
What version of Go are you using (
go version
)?go1.18-16d6a5233a Tue Jan 25 00:39:08 2022 +0000. Using gotipplay.golang.org.
Does this issue reproduce with the latest release?
No.
What operating system and processor architecture are you using (
go env
)?I am using gotipplay.golang.org.
What did you do?
What did you expect to see?
I expect p to be a
*[]int
What did you see instead?
A compile error. cannot convert &slice (value of type *Slice) to type *[]int.
The text was updated successfully, but these errors were encountered: