Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Properly format functions without the Tfun type.
Summary: There are some functions (like `idx`) which are special-cased by the typechecker, which means that even though its type is Function it doesn't have a Tfun. Right now we fall back to displaying these as if they were class members, due to a faulty match expression.
Differential Revision: D7418540
fbshipit-source-id: 01ff338788230187be2203deebdccecdcd2aed3e
Loading branch information
@@ -595,30 +595,27 @@ module Full = struct
in
let body =
let open SymbolOccurrence in
match occurrence with
| { type_ = Class ; name; _ } -> Concat [text " class " ; text_strip_ns name]
| { type_ = Function ; name; _ }
| { type_ = Method (_, name); _ }
| { type_ = Property (_, name); _ }
| { type_ = ClassConst (_, name); _ }
| { type_ = GConst ; name; _ } ->
match occurrence, x with
| { type_ = Class ; name; _ } , _ -> Concat [text " class " ; text_strip_ns name]
| { type_ = Function ; name; _ }, (_, Tfun ft)
| { type_ = Method (_ , name ); _ } , (_ , Tfun ft ) ->
(* Use short names for function types since they display a lot more
information to the user. *)
begin match x with
| ( _ , Tfun ft ) ->
Concat [
text " function " ;
text_strip_ns name;
fun_type text_strip_ns ISet. empty env ft;
]
| _ ->
Concat [
ty text_strip_ns ISet. empty env x;
Space ;
text_strip_ns (occurrence.name) ;
]
end
Concat [
text " function " ;
text_strip_ns name;
fun_type text_strip_ns ISet. empty env ft ;
]
| { type_ = Property _; name; _ }, _
| { type_ = ClassConst _; name; _ }, _
| { type_ = GConst ; name; _ } , _ ->
Concat [
ty text_strip_ns ISet. empty env x ;
Space ;
text_strip_ns name;
]
| _ -> ty text_strip_ns ISet. empty env x
in
@@ -19,8 +19,13 @@ let pos_at (line1, column1) (line2, column2) =
(File_pos. of_line_column_offset line1 (column1 - 1 ) 0 )
(File_pos. of_line_column_offset line2 column2 0 ))
let builtins = " <?hh // strict
class Awaitable<T> {}"
let builtins = " <?hh // decl
class Awaitable<T> {}
interface Traversable<+Tv> {}
interface KeyedTraversable<+Tk, +Tv> extends Traversable<Tv> {}
interface Container<+Tv> extends Traversable<Tv> {}
interface KeyedContainer<+Tk, +Tv> extends Container<Tv>, KeyedTraversable<Tk, Tv> {}
function idx<Tk, Tv>(?KeyedContainer<Tk, Tv> $collection, Tk $index, $default = null): ?Tv {}"
let class_members = " <?hh // strict
abstract class ClassMembers {
@@ -424,17 +429,38 @@ the other stars."; "Full name: `DocBlock::leadingStarsAndMDList`"];
]
]
let special_cases = " <?hh // strict
function special_cases(): void {
idx(array(1, 2, 3), 1);
//^3:3
}
"
let special_cases_cases = [
(" special_cases.php" , 3 , 3 ), [
{
(* Without the `ft` corresponding to the `Tfun`, we can't give any useful
information here :/ *)
snippet = " ?int" ;
addendum = [] ;
pos = pos_at (3 , 3 ) (3 , 24 );
}
]
]
let files = [
" builtins.php" , builtins;
" class_members.php" , class_members;
" classname_call.php" , classname_call;
" chained_calls.php" , chained_calls;
" classname_variable.php" , classname_variable;
" docblock.php" , docblock;
" special_cases.php" , special_cases;
]
let cases =
docblockCases
special_cases_cases
@ docblockCases
@ class_members_cases
@ classname_call_cases
@ chained_calls_cases
Toggle all file notes
Toggle all file annotations