[Issue 15153] New: CTFE failes to access second dimension of static arrays

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Oct 4 08:31:17 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15153

          Issue ID: 15153
           Summary: CTFE failes to access second dimension of static
                    arrays
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: tobias.marstaller at gmail.com

Created attachment 1553
  --> https://issues.dlang.org/attachment.cgi?id=1553&action=edit
Both snippets with compiler output

CTFE fails to access the second dimension of static arrays (even if explicitly
given).

This snipped throws the compiler error "variable nCols cannot be read at
compile time.":

--------------------------------------------------------------------------------
static int[][] staticTable = [[1, 2], [3, 4]];
static int[][] staticallyDerivedTable = deriveTable(staticTable);

static int[][] deriveTable(int[][] table)
{
    int nRows = table.length;
     int nCols = table[0].length;
     int[nCols][nRows] newTable;

    // ... do something

    return newTable;
}
--------------------------------------------------------------------------------
The error occurs in deriveTable(int[][]) where newTable is declared.

But even if the array sizes are explicitly given, the error stays:

--------------------------------------------------------------------------------
static int[2][2] staticTable = [[1, 2], [3, 4]];
static int[2][2] staticallyDerivedTable = deriveTable(staticTable);

static int[2][2] deriveTable(int[2][2] table)
{
    int nRows = table.length;
    int nCols = table[0].length;
    int[nCols][nRows] newTable;

    // ... do something

    return newTable;
}
--------------------------------------------------------------------------------


This might be related to #2569;

AFAICT my code is correct; in both cases the required information is available
at compile time. table.length does not throw an error so i guess the basics are
working fine already.

Since the staticTable is of fixed size, this is not that much of an issue to me
because i can hard-code the sizes; but that should not be required.

--


More information about the Digitalmars-d-bugs mailing list