VKCOM/kphp

Static method `new` is unsupported in generics

vkaverin opened this issue · 0 comments

<?php

class Foo {
}

_main();

function _main() {
  new_t(Foo::class);
}

/**
 * @kphp-generic T
 * @param class-string<T> $t
 */
function new_t($t) {
  $t::new();
}

fails to compile with following errors:

Compilation error at stage: Parse file, gen by gentree.cpp:1333
  4dbee3a5.php:18  in new_t<T>
    $t::new();

Unrecognized syntax after '$t::'


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation error at stage: Parse file, gen by gentree.cpp:1641
  4dbee3a5.php:18  in new_t<T>
    $t::new();

Failed to parse statement. Expected `;`

Changing call of ::new() to ::abc() gives correct error:

Compilation error at stage: Check func calls and vararg, gen by replace-extern-func-calls.cpp:91
  dd8b4e3e.php:18  in new_t<Foo> (instantiated at dd8b4e3e.php:10)
    $t::abc();

Syntax '$class_name::method()' not resolved: method abc not found in class Foo