-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: spec: make len(a), cap(a) const for some type parameters #65592
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
len(a)
/cap(a)
should be constant if a
's type is a type parameter constraint by arrays of the same length
len(a)
/cap(a)
should be constant if a
's type is a type parameter constraint by arrays of the same lengthlen(a)
/cap(a)
should be constant if a
's type is a type parameter constrained by arrays of the same length
Change https://go.dev/cl/562349 mentions this issue: |
Change https://go.dev/cl/562323 mentions this issue: |
I believe this is a counter-example that would stop type-checking with this change:
If we want to be strictly backwards-compatible, I think this semantic change needs to be tied to the language version like |
Bit-shift |
@mdempsky Indeed. Seems pretty esoteric, but it would break such code. Maybe not worth making this change. |
Similar to #28591 |
Honestly speaking, the change is quite small comparing to the loop var change. |
Since the change is not backwards compatible, it seems like we should leave things as they are. |
Retracting. |
len(a)
/cap(a)
should be constant if a
's type is a type parameter constrained by arrays of the same length
This proposal has been declined as infeasible. |
Proposal Details
The code
should be valid if the constraint
C
describes a type set containing only (pointer to) arrays and all arrays have the same length. Currently, the length and capacity of a type parameter value are always non-constant. Either way, the type is defined to beint
per the spec. Anint
constant value can be used wherever anint
non-constant value is permitted. Thus, this change is strictly backward-compatible; it simply increases the set of valid programs.See also #50226.
The text was updated successfully, but these errors were encountered: