Skip to content

Fixed array sizes: a negative size becomes 0, and absurd sizes are accepted #170

Open

Description

@Kinflou
struct S {
    a: u8[-3]                    // builds, as u8[0]
    b: u8[9223372036854775807]   // builds
}

TypeRef::from_grammar clamps a negative size with .max(0), so u8[-3] silently becomes u8[0]. Nothing caps a fixed size, so a field can declare more elements than any target can hold.

Fix: a negative size is an error, and so is an exact length of 0. Cap fixed sizes at u32::MAX, with each target's ceiling checked when generating. Both are part of the bounds design (core#98; issues 4 and 32 in docs' Proposal D).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2SoonbugSomething isn't workingcompilerParser, IR, CAS

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions