G
YouTube TikTok Games
Skip to content

Static method new is unsupported in generics #973

Open

Description

@vkaverin
<?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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions