Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve lambda parameter inference for mixed/dynamic
Summary: Adopts the following rule when dealing with expected type of a lambda is `mixed` or `dynamic`. ``` G, x : mixed/dynamic |- e : mixed/dynamic ----------------------------------------- G |- (\x -> e) : mixed/dynamic ``` Reviewed By: andrewjkennedy Differential Revision: D26200919 fbshipit-source-id: 5942210d650c4389558478c7999396d6b89c1233
- Loading branch information
1 parent
efa6463
commit bfd338f
Showing
12 changed files
with
111 additions
and
2 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,11 @@ | ||
<?hh | ||
|
||
class C { | ||
public function __construct( | ||
public dynamic $f, | ||
) {} | ||
} | ||
|
||
function f(): void { | ||
new C($x ==> $x + 1); | ||
} |
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 @@ | ||
No errors |
6 changes: 4 additions & 2 deletions
6
hphp/hack/test/typecheck/lambda/untyped_lambda_strict_mode.php.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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
File "untyped_lambda_strict_mode.php", line 5, characters 16-31: | ||
Cannot determine types of lambda parameters in strict mode. Please add type hints on parameters. (Typing[4224]) | ||
File "untyped_lambda_strict_mode.php", line 5, characters 27-29: | ||
You are trying to access the method `foo` but this is a mixed value. Use a **specific** class or interface name. (Typing[4064]) | ||
File "untyped_lambda_strict_mode.php", line 5, characters 16-17: | ||
Definition is here |
11 changes: 11 additions & 0 deletions
11
hphp/hack/test/typecheck/mixed_lambda_explicit_return_ko.php
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,11 @@ | ||
<?hh | ||
|
||
class C { | ||
public function __construct( | ||
public mixed $f, | ||
) {} | ||
} | ||
|
||
function f(): void { | ||
new C(($x) : int ==> $x); | ||
} |
6 changes: 6 additions & 0 deletions
6
hphp/hack/test/typecheck/mixed_lambda_explicit_return_ko.php.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,6 @@ | ||
File "mixed_lambda_explicit_return_ko.php", line 10, characters 24-25: | ||
Invalid return type (Typing[4110]) | ||
File "mixed_lambda_explicit_return_ko.php", line 10, characters 16-18: | ||
Expected `int` | ||
File "mixed_lambda_explicit_return_ko.php", line 5, characters 12-16: | ||
But got `mixed` |
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,11 @@ | ||
<?hh | ||
|
||
class C { | ||
public function __construct( | ||
public mixed $f, | ||
) {} | ||
} | ||
|
||
function f(): void { | ||
new C($x ==> $x + 1); | ||
} |
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 "mixed_lambda_ko.php", line 10, characters 16-21: | ||
Typing error (Typing[4110]) | ||
File "mixed_lambda_ko.php", line 10, characters 16-17: | ||
Expected `num` because this is used in an arithmetic operation | ||
File "mixed_lambda_ko.php", line 5, characters 12-16: | ||
But got `mixed` |
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,11 @@ | ||
<?hh | ||
|
||
class C { | ||
public function __construct( | ||
public mixed $f, | ||
) {} | ||
} | ||
|
||
function f(): void { | ||
new C($x ==> $x); | ||
} |
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 @@ | ||
No errors |
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,11 @@ | ||
<?hh | ||
|
||
class C { | ||
public function __construct( | ||
public mixed $f, | ||
) {} | ||
} | ||
|
||
function f(): void { | ||
new C(($x, string $y) ==> $y + 1); | ||
} |
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 "semi_mixed_lambda_ko.php", line 10, characters 29-34: | ||
Typing error (Typing[4110]) | ||
File "semi_mixed_lambda_ko.php", line 10, characters 29-30: | ||
Expected `num` because this is used in an arithmetic operation | ||
File "semi_mixed_lambda_ko.php", line 10, characters 14-19: | ||
But got `string` |