kphp icon indicating copy to clipboard operation
kphp copied to clipboard

Confusing error message for non-constant index for tuples and shapes

Open i582 opened this issue 5 years ago • 0 comments

Non-const values are not allowed when indexing stubs and shapes, but errors for such cases are very incomprehensible.

For example:

<?php
function f() {
    $s = shape(["key" => 12, "value" => 1]);
    $key = "value";
    echo $s[$key];
}

f();

Gives the following error:

Compilation error at stage: CheckConversions, gen by node-recalc.cpp:54
  script.php:11  in f
    echo $s[$key];

Type Error [ExprNode $s[.] at script.php:11  in f : any] updated by [ExprNode $s at script.php:11  in f : shape(key:int, value:int)]

The same goes for tuples.

I would like to see an error like this:

Non-const values are not allowed for indexing the shape

i582 avatar Jun 10 '21 11:06 i582