kphp icon indicating copy to clipboard operation
kphp copied to clipboard

Primitive type as `class-string`

Open vkaverin opened this issue 1 year ago • 2 comments

/**
 * @kphp-generic T
 * @param class-string<T> $t
 */
function foo($t) {
}

foo('int');

Compilation of this code fails with

Starting php to cpp transpiling...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation error at stage: Deduce implicit types and casts, gen by generics-reification.cpp:192
  a38a375e.php:9  in global scope


Class int not found


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compilation error at stage: Deduce implicit types and casts, gen by generics-reification.cpp:319
  a38a375e.php:9  in global scope


Couldn't reify generic <T> for call.
Please, provide all generic types using syntax foo/*<T>*/(...)

vkaverin avatar Mar 05 '23 15:03 vkaverin

Maybe it's worth to rename (or alias) the annotation into type-string to avoid confusing with by class?

vkaverin avatar Mar 07 '23 22:03 vkaverin

And don't forget about classof.

vkaverin avatar Mar 09 '23 23:03 vkaverin