Skip to content

Quality of life, misleading error messages when extracting values from a slice of a pointer (from vectors and slices) #2681

@joshring

Description

@joshring
import std::io;


macro transpose4x4_mat(a, b, c, d)
{
    Matrix4x4{float} mat;
   
    mat.m[0..3] = *a[..];
    mat.m[4..7] = *b[..];
    mat.m[8..11] = *c[..];
    mat.m[12..15] = *d[..];
    
    mat = mat.transpose();
    
    *a = mat.m[0..3];
    *b = mat.m[4..7];
    *c = mat.m[8..11];
    *d = mat.m[12..15];
}

fn void main() 
{
    float[<4>] a = { 0,1,2,3 };
    float[<4>] b = { 4,5,6,7 };
    float[<4>] c = { 8,9,10,11 };
    float[<4>] d = { 12,13,14,15 };
    
    transpose4x4_mat(&a, &b, &c, &d);
    
    io::printn(a);
    io::printn(b);
    io::printn(c);
    io::printn(d);
}

mat.m[0..3] = *a[..];
^^
(/home/josh/git/pffft_c3/src/pffft.c3:96:22) Error: Omitting end index is not allowed for pointers or flexible array members.

so then you think, ok i'll add the end index:

mat.m[0..3] = *a[..3];
^^^^^^
(/home/josh/git/pffft_c3/src/pffft.c3:96:20) Error: Cannot dereference a value of type 'float[<4>][]', it must be a pointer.

this is super confusing, the actual solutions are either:

mat.m[0..3] = (*a)[..];
// or
mat.m[0..3] = a.[..];

but neither of these solutions are mentioned in the error messages

This applies to both vectors and slices as input to this macro

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions