Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

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

Open
azjezz opened this issue Nov 30, 2020 · 2 comments

Comments

@azjezz
Copy link
Contributor

azjezz commented Nov 30, 2020

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

@fredemmott fredemmott changed the title TypeSpec\of() doesn't take reified generics into account. TypeSpec\of() doesn't take inner generics of arbitrary classes into account. Dec 1, 2020
@azjezz
Copy link
Contributor Author

azjezz commented Dec 2, 2020

related: facebook/hhvm#8772

@fredemmott fredemmott changed the title TypeSpec\of() doesn't take inner generics of arbitrary classes into account. TypeSpec\of() doesn't take inner reified generics of arbitrary classes into account. Sep 13, 2021
@lexidor
Copy link
Contributor

lexidor commented May 24, 2023

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants