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

Commit

Permalink
fix missing autoimported types (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjergus authored Sep 9, 2019
1 parent fe48e74 commit c60088b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/ResolvedTypeKind.hack
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ namespace Facebook\HHAST;
enum ResolvedTypeKind: string {
GENERIC_PARAMETER = 'generic_parameter';
QUALIFIED_TYPE = 'qualified_type';
QUALIFIED_AUTOIMPORTED_TYPE = 'qualified_autoimported_type';
CALLABLE = 'callable';
}
21 changes: 0 additions & 21 deletions src/__Private/Resolution/resolve_name.hack
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@ function resolve_name(
'Call on the class name without generics',
);

$autoimports = keyset[
'Awaitable',
'ConstMap',
'ConstSet',
'ConstVector',
'Container',
'ImmMap',
'ImmSet',
'ImmVector',
'KeyedContainer',
'KeyedTraversable',
'Map',
'Set',
'Stringish',
'Traversable',
'Vector',
];
if (C\contains_key($autoimports, $name)) {
return 'HH\\'.$name;
}

$ns = get_current_namespace($root, $node);

if (Str\contains($name, '\\')) {
Expand Down
61 changes: 60 additions & 1 deletion src/resolve_type.hack
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,64 @@ function resolve_type(
Script $root,
Node $node,
): shape('kind' => ResolvedTypeKind, 'name' => string) {
$uses = Resolution\get_current_uses($root, $node);
if ($type === 'callable') {
// Super special case. It's not a legal type anymore but still supported by
// runtime.
return shape(
'kind' => ResolvedTypeKind::CALLABLE,
'name' => 'callable',
);
}

// From hhvm/hphp/hack/src/parser/namespaces.ml
$autoimports = keyset[
'AsyncFunctionWaitHandle',
'AsyncGenerator',
'AsyncGeneratorWaitHandle',
'AsyncIterator',
'AsyncKeyedIterator',
'Awaitable',
'AwaitAllWaitHandle',
'Collection',
'ConditionWaitHandle',
'Container',
'ExternalThreadEventWaitHandle',
'IMemoizeParam',
'ImmMap',
'ImmSet',
'ImmVector',
'InvariantException',
'Iterable',
'Iterator',
'KeyedContainer',
'KeyedIterable',
'KeyedIterator',
'KeyedTraversable',
'Map',
'ObjprofObjectStats',
'ObjprofPathsStats',
'ObjprofStringStats',
'Pair',
'RescheduleWaitHandle',
'ResumableWaitHandle',
'Set',
'Shapes',
'SleepWaitHandle',
'StaticWaitHandle',
'Traversable',
'TypeStructure',
'TypeStructureKind',
'Vector',
'WaitableWaitHandle',
'XenonSample',
];

if (C\contains_key($autoimports, $type)) {
return shape(
'kind' => ResolvedTypeKind::QUALIFIED_AUTOIMPORTED_TYPE,
'name' => 'HH\\'.$type,
);
}

if (C\contains_key(Resolution\get_current_generics($root, $node), $type)) {
// Generic type names don't belong to a namespace, nothing to resolve.
Expand All @@ -27,6 +84,8 @@ function resolve_type(
);
}

$uses = Resolution\get_current_uses($root, $node);

if (C\contains_key($uses['types'], $type)) {
return shape(
'kind' => ResolvedTypeKind::QUALIFIED_TYPE,
Expand Down

0 comments on commit c60088b

Please sign in to comment.