Fix typehint for lambdas
commitcb43763fe5081fa937cc75efdfd59239f5dbf91e
authorGabe Levi <glevi@fb.com>
Wed, 9 Apr 2014 02:21:51 +0000 (8 19:21 -0700)
committerSara Golemon <sgolemon@fb.com>
Fri, 18 Apr 2014 07:13:59 +0000 (18 00:13 -0700)
tree470e3e73f51d7a1819f28aced97b12318cb0b6ea
parentccf06d57ebf7da5f9cab87dcdfa1439494a7e34b
Fix typehint for lambdas

Fixes #2370

Our parsing of short lambda arguments was super naive. They're basically the same thing as anonymous functions, so we need to support typehints, variadics, etc.

I can't say I love the pattern of trying to parse and seeing if it created any errors, but it works.

I also decided to add support for lambda return types. To make sure I covered everything I copied the hphp/test/quick/lambda*.php tests here, with a few small Hack related fixes (like `new bar` -> `new bar()`).

The one thing that Hack couldn't support was typing a lambda function with anonymous arguments. For example, I couldn't get this to work:

    (): (function(int): int) ==> (int $x = 4): int ==> $x;

Hack thinks that the arity doesn't match between these two functions. Internally we can deal with a function type with min/max arity, we just don't have syntax to declare it. Phooey.

Reviewed By: @jdelong

Differential Revision: D1266483
31 files changed:
hphp/hack/src/hh_single_type_check.ml
hphp/hack/src/parsing/parser_hack.ml
hphp/hack/test/more_tests/functional_option.php.exp
hphp/hack/test/more_tests/hhvm_lambda1.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda1.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda2.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda2.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda3.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda3.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda4.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda4.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda5.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda5.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda6.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda6.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda7.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda7.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda8.php [new file with mode: 0644]
hphp/hack/test/more_tests/hhvm_lambda8.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/lambda18.php [new file with mode: 0644]
hphp/hack/test/more_tests/lambda18.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/lambda19.php [new file with mode: 0644]
hphp/hack/test/more_tests/lambda19.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/lambda20.php [new file with mode: 0644]
hphp/hack/test/more_tests/lambda20.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/lambda21.php [new file with mode: 0644]
hphp/hack/test/more_tests/lambda21.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/lambda22.php [new file with mode: 0644]
hphp/hack/test/more_tests/lambda22.php.exp [new file with mode: 0644]
hphp/hack/test/more_tests/lambda23.php [new file with mode: 0644]
hphp/hack/test/more_tests/lambda23.php.exp [new file with mode: 0644]