-
Notifications
You must be signed in to change notification settings - Fork 18k
spec: should len(a)
(and cap(a)
) be constant for a
of type parameter type constrained by same-size arrays?
#50226
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
Comments
Note that the spec currently says:
If it said
and we look at In the implementation it would mean changing a call to cc: @ianlancetaylor |
Moving this to Go1.19 means it will be always as such. It is a problem same as |
BTW, it looks it is disallowed to pass addresses of array type parameter values to package main
func f[T [2]int]() {
var x T
const _ = len(&x) // invalid argument: &x (value of type *T) for len
var _ = len(&x) // invalid argument: &x (value of type *T) for len
}
func main() {
type T [2]int
var x T
const _ = len(&x) // okay
} |
Too late for 1.21 if anything needs to be done here. |
Moving to 1.23. We're not going to change this for 1.22. |
Looking at this some more, this just seems to be a bug. Sending out a fix for review/discussion. |
This is a (if minor) language change and thus needs to go through the proposal process. Closing this issue in favor of #65592. |
See also https://go.dev/cl/562349. |
Reminder issue to consider this case. See also #42029 for background.
This can wait for 1.19 as going from a non-constant to a constant result for
len
andcap
is a backward-compatible change (I think, since the type doesn't change, it's alwaysint
).The text was updated successfully, but these errors were encountered: