Skip to content

cast(T[1]) succeeds for structs and static arrays, but fails for basic types #22269

@Herringway

Description

@Herringway
struct Bar {
    int value;
}
void main() {
    auto bar = Bar(42);
    (cast(Bar[1])bar)[] = Bar(1); // OK!
    assert(bar.value == 1);
    int foo = 42;
    (cast(int[1])foo)[] = 1; // Error: cannot cast expression `foo` of type `int` to `int[1]`
    assert(foo == 1);
}

It is occasionally useful to be able to slice scalars (for use with std.stdio.File.rawWrite, for example), so I would like to see this more consistently supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions