kphp icon indicating copy to clipboard operation
kphp copied to clipboard

CompileTimeLocation argument fails if a function has default arguments before

Open tolk-vm opened this issue 2 years ago • 1 comments

https://sun9-37.userapi.com/s/v1/ig2/QxnygNlZyl5hjcni3Xij8tS09WPC__LCLiqgxImuSygAhbXYKqkLhJztFhFd1VLWRWDJv-bjMFZp8ejT19kH0JWF.jpg?size=1119x961&quality=96&type=album

tolk-vm avatar Apr 27 '22 06:04 tolk-vm

Сборка падает, если CompileTimeLocation перед необязательным аргументом, т.к. объект подставляется не на своё место.

Минимальный код для воспроизведения:

function logError(?int $code = null, \CompileTimeLocation $loc = null): string {
    $loc = \CompileTimeLocation::calculate($compile_time_location);
    return "test (in {$loc->function} at {$loc->file}:{$loc->line})\n";
  }

logError();

Вывод:

Starting php to cpp transpiling...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation error at stage: Calc actual calls, gen by type-inferer.cpp:53
  test.php:7  in global scope


pass CompileTimeLocation to argument $code of logError
but it's declared as @param ?int

  test.php:7  in global scope

    new CompileTimeLocation returns CompileTimeLocation


Compilation terminated due to errors

FlyInk13 avatar Sep 19 '22 13:09 FlyInk13