Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a new /* HH_TRACE[$var] */ annotation #8849

Open
azjezz opened this issue Jun 22, 2021 · 3 comments
Open

Introduce a new /* HH_TRACE[$var] */ annotation #8849

azjezz opened this issue Jun 22, 2021 · 3 comments

Comments

@azjezz
Copy link
Contributor

azjezz commented Jun 22, 2021

while analyzing a script, it would be nice to be able to inspect the type of a variable if it's not a parameter.

e.g:

$pattern = re"/(?P<language>PHP)/";

$pattern in this case is shape(0 => string, 'langauge' => string), however, the only way to know this statically, is by using an editor with hack plugin, which would ask hh_client for the information.

request

This issue requests a new hh_client "annotation" HH_TYPE/HH_TRACE which will result in an error that contains type information about given variable ( e.g: https://cloud.void.tn/c/36?version=4.114.0 )

This feature is inspired by psalm trace feature: https://psalm.dev/r/1602ca9415

@azjezz azjezz changed the title Introduce a new /* HH_TYPE[$var] */ flag Introduce a new /* HH_TRACE[$var] */ annotation Jun 22, 2021
@fredemmott
Copy link
Contributor

fredemmott commented Jun 23, 2021

There's hh_client --type-at-pos too, but yes, this is useful.

We have something very similar already in hh_single_type_check (used for our unit tests): a fake function called hh_show() that pretty much acts exactly as you're describing.

Perhaps this should be made available in real hh_client/hh_server runs too as HH\show_type_and_raise_error($x) or something like that.

@azjezz
Copy link
Contributor Author

azjezz commented Jun 23, 2021

I think there should be 2 functions.

here, the actual type is Regex\Pattern<shape(0 => string, 'language' => string)>, but the type to use in user-land is Regex\Pattern<shape('language' => string, ...)>

so we should have 2 variant of HH\show_type($pattern).

  1. to show the actual type ( internal, not possible in userland, could be a union, intersection, contains wildcard _, ... etc )
  2. to show the use-able type hint ( how can i type hint this in my code? )

@fredemmott
Copy link
Contributor

fredemmott commented Jun 23, 2021

2 should be identical to 1, unless 1 is not denotable at all.

If we did do a separate (2) it'd be something like HH\show_unsafe_more_permissive_denotable_type_and_error(), though I don't know if we reliably track the information required to implement that.

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

No branches or pull requests

3 participants