type-assert icon indicating copy to clipboard operation
type-assert copied to clipboard

TypeSpec\of() doesn't take inner reified generics of arbitrary classes into account.

Open azjezz opened this issue 4 years ago • 2 comments

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

azjezz avatar Nov 30 '20 19:11 azjezz

related: https://github.com/facebook/hhvm/issues/8772

azjezz avatar Dec 02 '20 13:12 azjezz

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 ints 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.

lexidor avatar May 24 '23 18:05 lexidor