type-assert
type-assert copied to clipboard
TypeSpec\of() doesn't take inner reified generics of arbitrary classes into account.
example:
final class A<reify T> {}
class B<reify T> {}
final class C<reify Ti, reify To> extends B<Ti> {}
<<__EntryPoint>>
function m(): void {
require_once __DIR__.'/vendor/autoload.hack';
\Facebook\AutoloadMap\initialize();
echo \Facebook\TypeSpec\of<C<string, A<int>>>()->toString();
}
expected output: C<string, A<int>>
actual output: C
related: https://github.com/facebook/hhvm/issues/8772
Sorry, I don't think HHVM exposes a Hack API (function) to dynamically query the reified type arguments of a value.
The names of the generic arguments to the type C<string, A<int>>
are accessible via the TypeStructure
. (The API TypeAssert uses to "reflect" over reified generics.) But if there is no dynamic way to check the inner types, the ->toString()
call would be the only place where the generics have any effect. This might create false expectations that the inner types are checked by ->assertType()
.
If you or anyone else knows a Hack function one could use to access the int
s from new C<int, int>()
, this might be a good idea to implement. Without this, I am not so sure if ->toString()
should promise more than ->assertType()
delivers.