Skip to content

syntax change for fixed arrays needs to be implemented #25183

@JalonSolov

Description

@JalonSolov

Fixed arrays can currently be declared either by [<size>]<type>{} for an empty array, or [<type cast>(value), value2, value3, ...]!.

However, a discussion was started by Alex in November 2024, here: https://discord.com/channels/592103645835821068/700746775962714232/1306274293054832800

The final decision was that fixed arrays should be changed to the following syntax
[<size>]<type>[<values>], or [..]<type>[<values>] where the literal .. for the size means the compiler should count the number of values between the second [ and ] pair.

Also, the [<size>] part can be specified multiple times for multi-dimensional arrays.

Examples:

arr1 := [4]f32[1 2 3 4]

arr2 := [4][4]f32[
 [1 2 3 4]
 [5 5 4 2]
 [0 1 3 0]
 [0 1 4 1]
]

// etc., etc.  The same arrays could also be entered as
arr3 := [..]f32[1 2 3 4]

arr4 := [..][..]f32[
 [1 2 3 4]
 [5 5 4 2]
 [0 1 3 0]
 [0 1 4 1]
]

// using literal numbers for sizes makes it explicit without anyone having to count
// the number of values again.

// using `..` for sizes means you can freely add/remove values, and the compiler
// will handle the changes by counting the number of values at compile time.

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

Labels

Type: SyntaxThe issue/PR is related to the V syntaxUnit: CompilerBugs/feature requests, that are related to the V compiler in general.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions