Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static method new is unsupported in generics #973

Open
vkaverin opened this issue Mar 22, 2024 · 0 comments
Open

Static method new is unsupported in generics #973

vkaverin opened this issue Mar 22, 2024 · 0 comments

Comments

@vkaverin
Copy link

<?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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant