Skip to content

Commit

Permalink
Add failing test for resolving generator target in condition expressions
Browse files Browse the repository at this point in the history
Summary:
When a generator's expression contains a reference to the generator target, the
type is not includedin the types() query. Note that the existing code only
handles the case where the condition is exactly a reference to the target, but
not cases where the reference is recursively contained within the condition
expression.

Reviewed By: vladima

Differential Revision: D59504875

fbshipit-source-id: 64ec240fb8ece23b3a29107234a14557289e399c
  • Loading branch information
stroxler authored and facebook-github-bot committed Jul 11, 2024
1 parent 7b0fcda commit 2f58187
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions source/server/test/queryTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,34 @@ let test_handle_types_query context =
|> QueryTestTypes.create_types_at_locations;
};
]))
>>= fun () ->
(* TODO: the coverage visitor does not handle scope correctly. we recurse into conditions in two
places: (1) from the main visitor, where we do not have the correct resolution object. (2) from
the special-case code in CreateDefinitionAndAnnotationLookupVisitor, where we only resolve the
outermost expression. Note that replacing `x==0` with `x` will include the reference to `x`,
but compound expressions fail. *)
assert_type_query_response_with_local_root
~source:{|[x for x in [0] if x==0]|}
~query:"types(path='test.py')"
(fun _ ->
Single
(Base.TypesByPath
[
{
Base.path = "test.py";
types =
[
1, 0, 1, 24, Type.list Type.integer;
1, 1, 1, 2, Type.integer;
1, 7, 1, 8, Type.integer;
1, 12, 1, 15, Type.list Type.integer;
1, 13, 1, 14, Type.literal_integer 0;
1, 19, 1, 23, Type.bool;
1, 22, 1, 23, Type.literal_integer 0;
]
|> QueryTestTypes.create_types_at_locations;
};
]))


let test_handle_references_used_by_file_query context =
Expand Down

0 comments on commit 2f58187

Please sign in to comment.