Skip to content

Commit

Permalink
repro like types in extract method
Browse files Browse the repository at this point in the history
Summary:
Repro bug T212089841  (unexpected like types in "Extract into method" refactor)

A reliable way to reproduce this bug is to add an explicit like type to the return position of a function and call the function.

Differential Revision: D68018235

fbshipit-source-id: a57e9c117723f9dc23ca9761fa2a5e753173808e
  • Loading branch information
mheiber authored and facebook-github-bot committed Jan 10, 2025
1 parent 3b5048b commit 5688a90
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions hphp/hack/test/ide_code_actions/extract_method/HH_FLAGS
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--config everything_sdt=false
--extra-builtin ../hhi/extraBuiltins.hhi
1 change: 1 addition & 0 deletions hphp/hack/test/ide_code_actions/extract_method/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
%{project_root}/hack/test/verify.py
%{project_root}/hack/test/review.sh
(glob_files %{project_root}/hack/test/ide_code_actions/extract_method/HH_FLAGS)
(glob_files %{project_root}/hack/test/ide_code_actions/hhi/*.hhi)
(glob_files %{project_root}/hack/test/ide_code_actions/extract_method/*.php)
(glob_files %{project_root}/hack/test/ide_code_actions/extract_method/*.exp))
(action
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?hh

class Klass {
public async function foo(vec<int> $vec): Awaitable<void> {
$y = ExtraBuiltins\genInt();
/*range-start*/
$x1 = $y;
$x2 = ExtraBuiltins\genInt()
/*range-end*/
echo $x1;
echo await $x2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Code actions available:
------------------------------------------
slog variable (CodeActionKind: refactor)
Extract into method (CodeActionKind: refactor) SELECTED

JSON for selected code action:
------------------------------------------
{
"diagnostics":[],
"edit":{
"changes":{
"FILE.php":[
{
"newText":" private function ${0:method0}(~Awaitable<int> $y): (~Awaitable<int>, ~Awaitable<int>) {\n $x1 = $y;\n $x2 = ExtraBuiltins\\genInt()\n return tuple($x1, $x2);\n }\n\n",
"range":{"end":{"character":0,"line":3},"start":{"character":0,"line":3}}
},
{
"newText":"list($x1, $x2) = $this->${0:method0}($y);",
"range":{"end":{"character":32,"line":7},"start":{"character":4,"line":6}}
}
]
}
},
"kind":"refactor",
"title":"Extract into method"
}

Applied edit for code action:
------------------------------------------
<?hh

class Klass {
private function ${0:method0}(~Awaitable<int> $y): (~Awaitable<int>, ~Awaitable<int>) {
$x1 = $y;
$x2 = ExtraBuiltins\genInt()
return tuple($x1, $x2);
}

public async function foo(vec<int> $vec): Awaitable<void> {
$y = ExtraBuiltins\genInt();
/*range-start*/
list($x1, $x2) = $this->${0:method0}($y);
/*range-end*/
echo $x1;
echo await $x2;
}
}

3 changes: 3 additions & 0 deletions hphp/hack/test/ide_code_actions/hhi/extraBuiltins.hhi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ExtraBuiltins;

async function genInt(): ~Awaitable<int>;

0 comments on commit 5688a90

Please sign in to comment.