Permalink
Browse files

Prevent generics on collection intrinsics until typechecking lands

Summary: FFP accepts generics on collection intrinsics of the form `vec<int>["a", "b"]` but typechecking is not implemented so the above expression does not error. This diff prevents this syntax until typechecking is implemented.

Reviewed By: jamesjwu

Differential Revision: D8671216

fbshipit-source-id: 114bf793acc74219f14db9d5427efcb98bb42a25
  • Loading branch information...
vassilmladenov authored and hhvm-bot committed Jul 2, 2018
1 parent f6be594 commit 2834d34eac8ecaca2863aa976b3b44257add9b83
@@ -819,6 +819,10 @@ let empty_fun_hdr =
; fh_ret_by_ref = false
}
let prevent_intrinsic_generic env node ty =
if not (is_missing ty) && not env.codegen then
raise_parsing_error env node SyntaxError.collection_intrinsic_generic
let rec pSimpleInitializer node env =
match syntax node with
| SimpleInitializer { simple_initializer_value; simple_initializer_equal } ->
@@ -1021,17 +1025,21 @@ and pExpr ?location:(location=TopLevel) : expr parser = fun node env ->
| DictionaryIntrinsicExpression
{ dictionary_intrinsic_keyword = kw
; dictionary_intrinsic_explicit_type = ty
; dictionary_intrinsic_members = members
; _ }
| KeysetIntrinsicExpression
{ keyset_intrinsic_keyword = kw
; keyset_intrinsic_explicit_type = ty
; keyset_intrinsic_members = members
; _ }
| VectorIntrinsicExpression
{ vector_intrinsic_keyword = kw
; vector_intrinsic_explicit_type = ty
; vector_intrinsic_members = members
; _ }
->
prevent_intrinsic_generic env node ty;
if env.is_hh_file || env.enable_hh_syntax then
Collection (pos_name kw env, couldMap ~f:pAField members env)
else
@@ -1059,9 +1067,15 @@ and pExpr ?location:(location=TopLevel) : expr parser = fun node env ->
| _ -> pos_name collection_name env in
Collection (collection_name, couldMap ~f:pAField members env)
| VarrayIntrinsicExpression { varray_intrinsic_members = members; _ } ->
| VarrayIntrinsicExpression
{ varray_intrinsic_members = members
; varray_intrinsic_explicit_type = ty; _ } ->
prevent_intrinsic_generic env node ty;
Varray (couldMap ~f:pExpr members env)
| DarrayIntrinsicExpression { darray_intrinsic_members = members; _ } ->
| DarrayIntrinsicExpression
{ darray_intrinsic_members = members
; darray_intrinsic_explicit_type = ty; _ } ->
prevent_intrinsic_generic env node ty;
Darray (couldMap ~f:pMember members env)
| ArrayIntrinsicExpression { array_intrinsic_members = members; _ }
| ArrayCreationExpression { array_creation_members = members; _ }
@@ -471,6 +471,7 @@ let invalid_yield =
let invalid_yield_from =
"`yield from` can only appear as a statement, after `return`, or on the right of an assignment"
let invalid_class_in_collection_initializer =
"Cannot use collection initialization for non-collection class."
let invalid_brace_kind_in_collection_initializer =
@@ -479,3 +480,6 @@ let invalid_brace_kind_in_collection_initializer =
let prefixed_invalid_string_kind = "Only double-quoted strings may be prefixed."
let non_re_prefix = "Only `re`-prefixed strings allowed."
let collection_intrinsic_generic =
"Cannot initialize collection builtins with type parameters"
@@ -271,3 +271,4 @@ val invalid_class_in_collection_initializer: string
val invalid_brace_kind_in_collection_initializer: string
val prefixed_invalid_string_kind : string
val non_re_prefix : string
val collection_intrinsic_generic: string
@@ -0,0 +1,9 @@
<?hh // strict
function f(): void {
$a = vec<int>[0, 1, 2];
$b = dict<string, int>["0" => 10, "1" => 11, "2" => 12];
$c = keyset<int>[0, 1, 2];
$d = varray<int>[0, 1, 2];
$e = darray<string, int>["0" => 10, "1" => 11, "2" => 12];
}
@@ -0,0 +1,2 @@
File "explicit_type_collection_intrinsic.php", line 4, characters 8-24:
Cannot initialize collection builtins with type parameters (Parsing[1002])

0 comments on commit 2834d34

Please sign in to comment.