Skip to content

proposal: spec: make len(a), cap(a) const for some type parameters #65592

Closed
@griesemer

Description

@griesemer

Proposal Details

The code

func _[A C](a A) {
   const _ = len(a) // or cap(a)
}

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 be int per the spec. An int constant value can be used wherever an int non-constant value is permitted. Thus, this change is strictly backward-compatible; it simply increases the set of valid programs.

See also #50226.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions