Permalink
Browse files

Make closure and soft type specifiers a parse error

Summary:
These hints may never be used with `is`-expressions because:
- We have no information on a function's inputs/output at runtime.
- Soft typehints would be meaningless when testing types.

Reviewed By: periodic1236, oulgen

Differential Revision: D7076934

fbshipit-source-id: 42639d367cfa6a73b384098d6abf3796ad87b935
  • Loading branch information...
kmeht authored and hhvm-bot committed Feb 25, 2018
1 parent ca49cc8 commit d9a87a147165e8ac847102bf164adcbc07fdf4cd
@@ -1746,6 +1746,18 @@ let expression_errors node parents is_hack is_hack_file hhvm_compat_mode errors
&& leading_width lambda_signature = 0
-> failwith "syntax error, unexpected T_LAMBDA_ARROW";
(* End of bug-port *)
| IsExpression
{ is_right_operand = hint
; _ } ->
begin match syntax hint with
| ClosureTypeSpecifier _ ->
make_error_from_node hint
(SyntaxError.invalid_is_expression_hint "Callable") :: errors
| SoftTypeSpecifier _ ->
make_error_from_node hint
(SyntaxError.invalid_is_expression_hint "Soft") :: errors
| _ -> errors
end
| _ -> errors (* Other kinds of expressions currently produce no expr errors. *)
let require_errors node parents hhvm_compat_mode trait_use_clauses errors =
@@ -392,6 +392,6 @@ let variadic_param_with_type_in_php name type_ =
^ type_ ^ "); variadic params with type constraints are not "
^ "supported in non-Hack files"
let final_property = "Properties cannot be declared final"
let property_has_multiple_visibilities name =
"Multiple access type modifiers are not allowed: properties of " ^ name
let invalid_is_expression_hint hint = hint ^ " typehints cannot be used with `is` expressions"
@@ -237,3 +237,4 @@ val self_or_parent_colon_colon_class_outside_of_class : string -> string
val variadic_param_with_type_in_php : string -> string -> string
val final_property : string
val property_has_multiple_visibilities : string -> string
val invalid_is_expression_hint : string -> string
@@ -0,0 +1 @@
(13,16)-(13,32) Callable typehints cannot be used with `is` expressions
@@ -0,0 +1,14 @@
<?hh
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "hack" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
function test(mixed $e): bool {
return $e is (function(): int);
}
@@ -0,0 +1 @@
(13,16)-(13,19) Soft typehints cannot be used with `is` expressions
@@ -0,0 +1,14 @@
<?hh
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "hack" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
function test(mixed $e): bool {
return $e is @int;
}
@@ -191,6 +191,8 @@ let error_tests =
make_test_case_from_files testname test_errors in
List.map
[
"is_expression/test_callable_hint";
"is_expression/test_soft_hint";
"test_default_param_errors";
"test_alias_errors";
"test_method_modifier_errors";

0 comments on commit d9a87a1

Please sign in to comment.