-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better detection of early solve failure
Summary: In expand_type_and_solve, we detect whether we solve invariant type variables to nothing. The logic however is brittle. For example, if the type at hand is (#1 & nonnull) and #1 gets solved to nothing, it would fail to detect it, and therefore fail to fail. Same goes if the type at hand is (#1 | #2). Reviewed By: andrewjkennedy Differential Revision: D18635991 fbshipit-source-id: 33ce9d1b0630b1a8bf01ecdccf8d05363ce16072
- Loading branch information
1 parent
6565533
commit 69659ca
Showing
7 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?hh | ||
|
||
function test(Vector<int> $v): void { | ||
$m = Map {}; | ||
|
||
foreach ($v as $i) { | ||
if ($m->containsKey("a")) { | ||
$current_m = $m->get("a"); | ||
if ($current_m !== null) { | ||
$current_m->add($i); | ||
} | ||
} else { | ||
$m["a"] = Vector {$i}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
File "early_solve_inter.php", line 10, characters 9-18: | ||
Was expecting an object but type is unknown (Typing[4297]) | ||
File "early_solve_inter.php", line 4, characters 8-13: | ||
It is unknown because type parameter Tv of HH\Map could not be determined. Please add explicit type parameters to the invocation of HH\Map | ||
File "collections/Map.hhi", line 475, characters 32-33: | ||
via this generic Tv |
8 changes: 8 additions & 0 deletions
8
hphp/hack/test/typecheck/early_solve_inter.php.like_types.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
File "early_solve_inter.php", line 13, characters 7-27: | ||
Invalid assignment (Typing[4110]) | ||
File "early_solve_inter.php", line 4, characters 8-13: | ||
Expected nothing because type parameter Tv of HH\Map could not be determined. Please add explicit type parameters to the invocation of HH\Map | ||
File "collections/Map.hhi", line 475, characters 32-33: | ||
via this generic Tv | ||
File "early_solve_inter.php", line 13, characters 17-27: | ||
But got Vector<[unresolved]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?hh | ||
|
||
function test(Vector<int> $v): void { | ||
$m = Map {}; | ||
|
||
foreach ($v as $i) { | ||
if ($m->containsKey("a")) { | ||
$current_m = $m->get("a"); | ||
if ($current_m is nonnull) { | ||
$current_m->add($i); | ||
} | ||
} else { | ||
$m["a"] = Vector {$i}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
File "early_solve_inter2.php", line 10, characters 9-18: | ||
Was expecting an object but type is unknown (Typing[4297]) | ||
File "early_solve_inter2.php", line 4, characters 8-13: | ||
It is unknown because type parameter Tv of HH\Map could not be determined. Please add explicit type parameters to the invocation of HH\Map | ||
File "collections/Map.hhi", line 475, characters 32-33: | ||
via this generic Tv |
8 changes: 8 additions & 0 deletions
8
hphp/hack/test/typecheck/early_solve_inter2.php.like_types.exp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
File "early_solve_inter2.php", line 13, characters 7-27: | ||
Invalid assignment (Typing[4110]) | ||
File "early_solve_inter2.php", line 4, characters 8-13: | ||
Expected nothing because type parameter Tv of HH\Map could not be determined. Please add explicit type parameters to the invocation of HH\Map | ||
File "collections/Map.hhi", line 475, characters 32-33: | ||
via this generic Tv | ||
File "early_solve_inter2.php", line 13, characters 17-27: | ||
But got Vector<[unresolved]> |