Multiply entities beyond necessity even more (force better build parallelism)
[hiphop-php.git] / hphp / hack / src / parser / full_fidelity_syntax_error.ml
blobc4ce402d5a7a4bc4ed25088a65fac56719514a23
1 (*
2 * Copyright (c) 2016, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 (* TODO: Integrate these with the rest of the Hack error messages. *)
12 type error_type =
13 | ParseError
14 | RuntimeError
15 [@@deriving show]
17 type t = {
18 child: t option;
19 start_offset: int;
20 end_offset: int;
21 error_type: error_type;
22 message: string;
24 [@@deriving show]
26 exception ParserFatal of t * Pos.t
28 let make
29 ?(child = None) ?(error_type = ParseError) start_offset end_offset message
31 { child; error_type; start_offset; end_offset; message }
33 let rec to_positioned_string error offset_to_position =
34 let child =
35 match error.child with
36 | Some child ->
37 Printf.sprintf "\n %s" (to_positioned_string child offset_to_position)
38 | _ -> ""
40 let (sl, sc) = offset_to_position error.start_offset in
41 let (el, ec) = offset_to_position error.end_offset in
42 Printf.sprintf "(%d,%d)-(%d,%d) %s%s" sl sc el ec error.message child
44 let compare err1 err2 =
45 if err1.start_offset < err2.start_offset then
47 else if err1.start_offset > err2.start_offset then
49 else if err1.end_offset < err2.end_offset then
51 else if err1.end_offset > err2.end_offset then
53 else
56 let exactly_equal err1 err2 =
57 err1.start_offset = err2.start_offset
58 && err1.end_offset = err2.end_offset
59 && err1.message = err2.message
61 let expected_as_or_insteadof =
62 "The 'as' keyword or the 'insteadof' keyword is expected here."
64 let error_type err = err.error_type
66 let message err = err.message
68 let start_offset err = err.start_offset
70 let end_offset err = err.end_offset
72 (* Lexical errors *)
73 let error0001 = "A hexadecimal literal needs at least one digit."
75 let error0002 = "A binary literal needs at least one digit."
77 let error0003 =
78 "A floating point literal with an exponent needs at least "
79 ^ "one digit in the exponent."
81 let error0006 = "This character is invalid."
83 let error0007 = "This delimited comment is not terminated."
85 let error0008 = "A name is expected here."
87 let error0010 = "A single quote is expected here."
89 let error0011 = "A newline is expected here."
91 let error0012 = "This string literal is not terminated."
93 let error0013 = "This XHP body is not terminated."
95 let error0014 = "This XHP comment is not terminated."
97 (* Syntactic errors *)
98 let error1001 = "A .php file must begin with '<?hh'."
100 let error1003 = "The 'function' keyword is expected here."
102 let error1004 = "A name is expected here."
104 let error1006 = "A right brace ('}') is expected here."
106 let error1007 = "A type specifier is expected here."
108 let error1008 = "A variable name is expected here."
110 let error1010 = "A semicolon (';') is expected here."
112 let error1011 = "A right parenthesis (')') is expected here."
114 let error1013 = "A closing angle bracket ('>') is expected here."
116 let error1014 = "A closing angle bracket ('>') or comma is expected here."
118 let error1015 = "An expression is expected here."
120 let error1016 = "An assignment is expected here."
122 let error1017 = "An XHP attribute value is expected here."
124 let error1018 = "The 'while' keyword is expected here."
126 let error1019 = "A left parenthesis ('(') is expected here."
128 let error1020 = "A colon (':') is expected here."
130 let error1021 = "An opening angle bracket ('<') is expected here."
132 (* TODO: Remove this; redundant to 1009. *)
133 let error1022 = "A right parenthesis ('>') or comma (',') is expected here."
135 let error1023 = "An 'as' keyword is expected here."
137 let error1025 = "A shape field name is expected here."
139 let error1026 = "An opening square bracket ('[') is expected here."
141 let error1028 = "An arrow ('=>') is expected here."
143 let error1029 = "A closing double angle bracket ('>>') is expected here."
145 let error1031 =
146 "A comma (',') or a closing square bracket (']') is expected here."
148 let error1032 = "A closing square bracket (']') is expected here."
150 (* TODO: Break this up according to classish type *)
151 let error1033 =
152 "A class member, method, type, trait usage, trait require, "
153 ^ "xhp attribute, xhp use, or xhp category is expected here."
155 let error1034 = "A left brace ('{') is expected here."
157 let error1035 = "The 'class' keyword is expected here."
159 let error1036 = "An equals sign ('=') is expected here."
161 let error1037 = "Either 'abstract' or 'final' keyword is expected here."
163 let error1038 = "A semicolon (';') or a namespace body is expected here."
165 let error1039 = "A closing XHP tag is expected here."
167 let error1041 = "A function body or a semicolon (';') is expected here."
169 let error1044 = "A name or __construct keyword is expected here."
171 let error1045 = "An 'extends' or 'implements' keyword is expected here."
173 let error1046 = "A lambda arrow ('==>') is expected here."
175 let error1047 = "A scope resolution operator ('::') is expected here."
177 let error1048 = "A name, variable name or 'class' is expected here."
179 let error1050 = "A name or variable name is expected here."
181 let error1051 = "The 'required' or 'lateinit' keyword is expected here."
183 let error1052 = "An XHP category name beginning with a '%' is expected here."
185 let error1053 = "An XHP name or category name is expected here."
187 let error1054 = "A comma (',') is expected here."
189 let error1055 =
190 "A fallthrough directive can only appear at the end of"
191 ^ " a switch section."
193 (* TODO(20052790): use the specific token's text in the message body. *)
194 let error1056 = "This token is not valid as part of a function declaration."
196 let error1057 text = "Encountered unexpected token '" ^ text ^ "'."
198 let error1058 received required =
199 Printf.sprintf
200 ("Encountered unexpected " ^^ "token '%s'. Did you mean '%s'?")
201 received
202 required
204 let error1059 terminator =
205 Printf.sprintf
206 "An '%s' is required when using alternate block syntax."
207 (Full_fidelity_token_kind.to_string terminator)
209 let error1060 =
210 "Leading markup and `<?hh` are not permitted in `.hack` "
211 ^ "files, which are always strict."
213 let error1061 = "A Pocket Universes operator (':@') is expected here."
215 let error1062 = "References in use lists are not supported in Hack."
217 let error2001 = "A type annotation is required in strict mode."
219 let error2003 = "A case statement may only appear directly inside a switch."
221 let error2004 = "A default statement may only appear directly inside a switch."
223 let error2005 = "A break statement may only appear inside a switch or loop."
225 let error2006 = "A continue statement may only appear inside a loop."
227 let error2007 = "A try statement requires a catch or a finally clause."
229 let error2008 =
230 "The first statement inside a switch statement must "
231 ^ "be a case or default label statement."
233 let error2009 class_name method_name =
234 Printf.sprintf "Constructor %s::%s() cannot be static" class_name method_name
236 let error2010 =
237 "Parameters cannot have visibility modifiers (except in "
238 ^ "parameter lists of constructors)."
240 let error2013 = "A method declaration cannot have duplicate modifiers."
242 let error2014 = "An abstract method cannot have a method body."
244 let error2015 class_name method_name =
245 Printf.sprintf
246 "Non-abstract method %s::%s must contain body"
247 class_name
248 method_name
250 let error2016 class_name method_name =
251 Printf.sprintf
252 "Cannot declare abstract method %s::%s private"
253 class_name
254 method_name
256 let error2017 =
257 "A method declaration cannot have multiple visibility modifiers."
259 let error2018 = "A constructor cannot have a non-void type annotation."
261 let error2019 class_name method_name =
262 Printf.sprintf
263 "Cannot declare abstract method %s::%s final"
264 class_name
265 method_name
267 let error2020 =
268 "Use of the '{}' subscript operator is deprecated; " ^ " use '[]' instead."
270 let error2021 =
271 "A variadic parameter ('...') may only appear at the end of "
272 ^ "a parameter list."
274 let error2022 = "A variadic parameter ('...') may not be followed by a comma."
276 let error2023 =
277 "Abstract constructors cannot have parameters with visibility modifiers"
279 let error2024 =
280 "Traits or interfaces cannot have parameters with visibility modifiers"
282 let error2025 class_name prop_name =
283 Printf.sprintf "Cannot redeclare %s::%s" class_name prop_name
285 let error2029 = "Only traits and interfaces may use 'require extends'."
287 let error2030 = "Only traits may use 'require implements'."
289 let error2031 =
290 "A class, interface, or trait declaration cannot have duplicate modifiers."
292 let error2032 = "The array type is not allowed in strict mode."
294 let error2033 =
295 "The splat operator ('...') for unpacking variadic arguments "
296 ^ "may only appear at the end of an argument list."
298 let error2034 =
299 "A type alias declaration cannot both use 'type' and have a "
300 ^ "constraint. Did you mean 'newtype'?"
302 let error2035 = "Only classes may implement interfaces."
304 let error2036 =
305 "Only interfaces and classes may extend other interfaces and " ^ "classes."
307 let error2037 = "A class may extend at most one other class."
309 let error2038 constructor_name =
310 "A constructor initializing an object must be passed a (possibly empty) "
311 ^ "list of arguments. Did you mean 'new "
312 ^ constructor_name
313 ^ "()'?"
315 let error2039 classish_keyword classish_name function_name =
316 Printf.sprintf
317 ( "Cannot define a class, interface, or trait inside a function. Currently "
318 ^^ "%s '%s' is inside function '%s'." )
319 classish_keyword
320 classish_name
321 function_name
323 let error2040 =
324 "Invalid use of 'list(...)'. A list expression may only be "
325 ^ "used as the left side of a simple assignment, the value clause of a "
326 ^ "foreach loop, or a list item nested inside another list expression."
328 let error2041 =
329 "Unexpected method body: interfaces may contain only"
330 ^ " method signatures, and not method implementations."
332 let error2042 = "Interfaces may not be declared 'abstract'."
334 let error2043 = "Traits may not be declared 'abstract'."
336 let error2044 class_name method_name =
337 Printf.sprintf
338 ( "Classes cannot both "
339 ^^ "contain abstract methods and be non-abstract. Either declare 'abstract "
340 ^^ "class %s', or make 'function %s' non-abstract." )
341 class_name
342 method_name
344 let error2045 = "No method inside an interface may be declared 'abstract'."
346 let error2046 method_type =
347 Printf.sprintf
348 "'async' cannot be used on %s. Use an Awaitable<...> return type instead."
349 method_type
351 let error2047 visibility_modifier =
352 "Methods inside of interfaces may not be "
353 ^ "marked '"
354 ^ visibility_modifier
355 ^ "'; only 'public' visibility is allowed."
357 let error2048 = "Expected group use prefix to end with '\\'"
359 let error2049 = "A namespace use clause may not specify the kind here."
361 let error2050 = "A concrete constant declaration must have an initializer."
363 let const_static_prop_init =
364 "A const static property must have an initializer."
366 let error2051 =
367 "An abstract constant declaration must not have an initializer."
369 let abstract_prop_init = "An abstract property must not have an initializer."
371 let error2052 =
372 "Cannot mix bracketed namespace declarations with "
373 ^ "unbracketed namespace declarations"
375 let error2053 =
376 "Use of 'var' as synonym for 'public' in declaration disallowed in Hack. "
377 ^ "Use 'public' instead."
379 let error2054 =
380 "Method declarations require a visibility modifier "
381 ^ "such as public, private or protected."
383 let error2055 = "At least one enumerated item is expected."
385 let error2056 = "First unbracketed namespace occurrence here"
387 let error2057 = "First bracketed namespace occurrence here"
389 let error2058 = "Property may not be abstract."
391 let abstract_instance_property = "Instance property may not be abstract."
393 let invalid_shape_field_name =
394 "Shape field name must be a nonempty single-quoted string or a class constant"
396 let shape_field_int_like_string =
397 "Shape field name must not be an int-like string (i.e. \"123\")"
399 let error2061 =
400 "Non-static instance variables are not allowed in abstract "
401 ^ "final classes."
403 let error2062 = "Non-static methods are not allowed in abstract final classes."
405 let error2063 = "Expected integer or string literal."
407 let error2064 = "Reference methods are not allowed in strict mode."
409 let error2065 = "A variadic parameter ('...') must not have a default value."
411 (* This was typing error 4077. *)
412 let error2066 =
413 "A previous parameter has a default value. Remove all the "
414 ^ "default values for the preceding parameters, or add a default value to "
415 ^ "this one."
417 let error2067 = "A hack source file cannot contain '?>'."
419 let error2068 = "hh blocks and php blocks cannot be mixed."
421 let error2070 ~open_tag ~close_tag =
422 Printf.sprintf
423 "XHP: mismatched tag: '%s' not the same as '%s'"
424 close_tag
425 open_tag
427 let error2071 s = "Decimal number is too big: " ^ s
429 let error2072 s = "Hexadecimal number is too big: " ^ s
431 let error2073 =
432 "A variadic parameter ('...') cannot have a modifier "
433 ^ "that changes the calling convention, like 'inout'."
435 let error2074 call_modifier =
436 "An '" ^ call_modifier ^ "' parameter must not " ^ "have a default value."
438 let error2075 call_modifier =
439 "An '"
440 ^ call_modifier
441 ^ "' parameter cannot "
442 ^ "be passed by reference ('&')."
444 let error2076 = "Cannot use both 'inout' and '&' on the same argument."
446 let error2077 = "Cannot use empty list"
448 let error2078 = "Superglobals may not be taken by reference."
450 let list_must_be_lvar =
451 "list() can only be used as an lvar. Did you mean to use tuple()?"
453 let globals_without_subscript = "$GLOBALS access requires a subscript."
455 (* Start giving names rather than numbers *)
456 let async_not_last =
457 "The 'async' modifier must be directly before the 'function' keyword."
459 let uppercase_kw text = "Keyword " ^ text ^ " must be written in lowercase"
461 let using_st_function_scoped_top_level =
462 "Using statement in function scoped form may only be used at the top "
463 ^ "level of a function or a method"
465 let const_in_trait = "Traits cannot have constants"
467 let const_visibility =
468 "Class constants cannot have visibility modifiers in " ^ "Hack files"
470 let type_const_visibility = "Type constants cannot have visibility modifiers"
472 let strict_namespace_hh =
473 "To use strict Hack, place // strict after the open tag. "
474 ^ "If it's already there, remove this line. "
475 ^ "Hack is strict already."
477 let original_definition = "Original definition"
479 let name_is_already_in_use_php ~name ~short_name =
480 "Cannot use "
481 ^ name
482 ^ " as "
483 ^ short_name
484 ^ " because the name is already in use"
486 let name_is_already_in_use_hh ~line_num ~name ~short_name =
487 "Cannot use "
488 ^ name
489 ^ " as "
490 ^ short_name
491 ^ " because the name was explicitly used earlier via a `use' statement on line "
492 ^ string_of_int line_num
494 let name_is_already_in_use_implicit_hh ~line_num ~name ~short_name =
495 "Cannot use "
496 ^ name
497 ^ " as "
498 ^ short_name
499 ^ " because the name was implicitly used on line "
500 ^ string_of_int line_num
501 ^ "; implicit use of names from the HH namespace can be suppressed by adding an explicit `use' statement earlier in the current namespace block"
503 let declared_name_is_already_in_use_implicit_hh ~line_num ~name ~short_name:_ =
504 "Cannot declare class "
505 ^ name
506 ^ " because the name was implicitly used on line "
507 ^ string_of_int line_num
508 ^ "; implicit use of names from the HH namespace can be suppressed by adding an explicit `use' statement earlier in the current namespace block"
510 let declared_name_is_already_in_use ~line_num ~name ~short_name:_ =
511 "Cannot declare class "
512 ^ name
513 ^ " because the name was explicitly used earlier via a `use' statement on line "
514 ^ string_of_int line_num
516 let namespace_name_is_already_in_use ~name ~short_name =
517 "Cannot use namespace "
518 ^ name
519 ^ " as "
520 ^ short_name
521 ^ " because the name is already in use"
523 let function_name_is_already_in_use ~name ~short_name =
524 "Cannot use function "
525 ^ name
526 ^ " as "
527 ^ short_name
528 ^ " because the name is already in use"
530 let empty_method_name = "Expected a method name"
532 let const_name_is_already_in_use ~name ~short_name =
533 "Cannot use const "
534 ^ name
535 ^ " as "
536 ^ short_name
537 ^ " because the name is already in use"
539 let type_name_is_already_in_use ~name ~short_name =
540 "Cannot use type "
541 ^ name
542 ^ " as "
543 ^ short_name
544 ^ " because the name is already in use"
546 let variadic_reference = "Variadic '...' should be followed by a '$variable'"
548 let reference_variadic = "Variadic parameters cannot be taken by reference"
550 let double_variadic = "Parameter redundantly marked as variadic ('...')."
552 let double_reference = "Parameter redundantly marked as reference ('&')."
554 let global_in_const_decl = "Cannot have globals in constant declaration"
556 let parent_static_const_decl =
557 "Cannot use static or parent::class in constant declaration"
559 let parent_static_prop_decl =
560 "Cannot use static or parent::class in property declaration"
562 let conflicting_trait_require_clauses ~name =
563 "Conflicting requirements for '" ^ name ^ "'"
565 let shape_type_ellipsis_without_trailing_comma =
566 "A comma is required before the ... in a shape type"
568 let yield_in_magic_methods =
569 "'yield' is not allowed in constructors or magic methods"
571 let reference_not_allowed_on_key =
572 "Key of collection element cannot " ^ "be marked as reference"
574 let reference_not_allowed_on_value =
575 "Value of collection element cannot " ^ "be marked as reference"
577 let reference_not_allowed_on_element =
578 "Collection element cannot " ^ "be marked as reference"
580 let yield_outside_function = "Yield can only be used inside a function"
582 let reference_param_in_construct =
583 "Constructors cannot take parameters by reference"
585 let coloncolonclass_on_dynamic =
586 "Dynamic class names are not allowed in compile-time ::class fetch"
588 let enum_elem_name_is_class = "Enum element cannot be named 'class'"
590 let expected_dotdotdot = "'...' is expected here."
592 let not_allowed_in_write what = what ^ " is not allowed in write context"
594 let references_not_allowed =
595 "References are only allowed as function call arguments"
597 let reassign_this = "Cannot re-assign $this"
599 let this_in_static = "Don't use $this in a static method, use static:: instead"
601 let async_magic_method ~name =
602 "cannot declare constructors and magic methods such as '" ^ name ^ "' async"
604 let call_static_method = "__callStatic methods are no longer supported"
606 let reserved_keyword_as_class_name class_name =
607 "Cannot use '" ^ class_name ^ "' as class name as it is reserved"
609 let xhp_class_multiple_category_decls =
610 "An XHP class cannot have multiple category declarations"
612 let xhp_class_multiple_children_decls =
613 "An XHP class cannot have multiple children declarations"
615 let inout_param_in_generator =
616 "Parameters may not be marked inout on generators"
618 let inout_param_in_async_generator =
619 "Parameters may not be marked inout on async generators"
621 let inout_param_in_async =
622 "Parameters may not be marked inout on async functions"
624 let inout_param_in_construct =
625 "Parameters may not be marked inout on constructors"
627 let fun_arg_inout_set =
628 "You cannot set an inout decorated argument while calling a function"
630 let fun_arg_inout_const = "You cannot decorate a constant as inout"
632 let fun_arg_invalid_arg = "You cannot decorate this argument as inout"
634 let fun_arg_inout_containers =
635 "Parameters marked inout must be contained in locals, vecs, dicts, keysets,"
636 ^ " and arrays"
638 let memoize_with_inout =
639 "<<__Memoize>> cannot be used on functions with inout parameters"
641 let fn_with_inout_and_ref_params =
642 "Functions may not use both reference and inout parameters"
644 let method_calls_on_xhp_attributes =
645 "Method calls are not allowed on XHP attributes"
647 let method_calls_on_xhp_expression =
648 "Please add parentheses around the XHP component"
650 let invalid_constant_initializer = "Invalid expression in constant initializer"
652 let no_args_in_halt_compiler =
653 "__halt_compiler function does not accept any arguments"
655 let no_async_before_lambda_body =
656 "Unexpected use of async {...} as lambda expression"
658 let halt_compiler_top_level_only =
659 "__halt_compiler function should appear only at the top level"
661 let trait_alias_rule_allows_only_final_and_visibility_modifiers =
662 "Only 'final' and visibility modifiers are allowed in trait alias rule"
664 let namespace_decl_first_statement =
665 "Namespace declaration statement has to be the very first statement in the script"
667 let code_outside_namespace = "No code may exist outside of namespace {}"
669 let invalid_number_of_args name n =
670 "Method " ^ name ^ " must take exactly " ^ string_of_int n ^ " arguments"
672 let invalid_args_by_ref name =
673 "Method " ^ name ^ " cannot take arguments by reference"
675 let redeclaration_error name = "Cannot redeclare " ^ name
677 let class_with_abstract_method name =
678 "Class "
679 ^ name
680 ^ " contains an abstract method and must "
681 ^ "therefore be declared abstract"
683 let interface_has_private_method =
684 "Access type for interface method must be omitted"
686 let redeclaration_of_function ~name ~loc =
687 "Cannot redeclare " ^ name ^ "() (previously declared in " ^ loc ^ ")"
689 let redeclaration_of_method ~name = "Redeclared method " ^ name
691 let self_or_parent_colon_colon_class_outside_of_class name =
692 "Cannot access " ^ name ^ "::class when no class scope is active"
694 let property_has_multiple_visibilities name =
695 "Multiple access type modifiers are not allowed: properties of " ^ name
697 let property_has_multiple_modifiers name =
698 "Multiple modifiers are not allowed: properties of " ^ name
700 let property_requires_visibility =
701 "Property declarations require a visibility modifier "
702 ^ "such as public, private or protected."
704 let invalid_is_as_expression_hint n hint =
705 hint ^ " typehints cannot be used with " ^ n ^ "-expressions"
707 let elvis_operator_space = "An Elvis operator ('?:') is expected here."
709 let autoload_takes_one_argument = "__autoload() must take exactly 1 argument"
711 let clone_takes_no_arguments class_name method_name =
712 Printf.sprintf
713 "Method %s::%s cannot accept any arguments"
714 class_name
715 method_name
717 let clone_cannot_be_static class_name method_name =
718 Printf.sprintf
719 "Clone method %s::%s() cannot be static"
720 class_name
721 method_name
723 let namespace_not_a_classname = "Namespace cannot be used as a classname"
725 let missing_double_quote =
726 (* error0010 analogue *)
727 "A double quote is expected here."
729 let for_with_as_expression =
730 "For loops can not use as-expressions. Did you mean foreach?"
732 let sealed_val_not_classname =
733 "Values in sealed whitelist must be classname constants."
735 let sealed_final = "Classes cannot be both final and sealed."
737 let sealed_enum = "Enums cannot be sealed."
739 let interface_implements =
740 "Interfaces may not implement other interfaces or classes"
742 let memoize_on_lambda =
743 "<<__Memoize>> attribute is not allowed on lambdas or anonymous functions."
745 let memoize_lsb_on_non_static =
746 "<<__MemoizeLSB>> can only be applied to static methods"
748 let memoize_lsb_on_non_method =
749 "<<__MemoizeLSB>> can only be applied to methods"
751 let constants_as_attribute_arguments =
752 "User-defined constants are not allowed in user attribute expressions"
754 let instanceof_invalid_scope_resolution =
755 "A scope resolution (::) on the right side of an "
756 ^ "instanceof operator must start with a class name, `self`, `parent`, or `static`, and end with "
757 ^ "a variable"
759 let instanceof_memberselection_inside_scoperesolution =
760 "A scope resolution (::) on the right "
761 ^ "side of an instanceof operator cannot contain a member selection (->)"
763 let instanceof_missing_subscript_index =
764 "A subscript expression ([]) on the right side of an "
765 ^ "instanceof operator must have an index"
767 let instanceof_new_unknown_node msg =
768 Printf.sprintf
769 "Unexpected node on right hand side of new or instanceof: %s"
772 let instanceof_reference =
773 "References are not allowed on the right side of an instanceof operation"
775 let instanceof_disabled =
776 "The 'instanceof' operator is not supported in Hack; use the 'is' operator or 'is_a()'"
778 let invalid_await_use = "Await cannot be used as an expression"
780 let toplevel_await_use = "Await cannot be used in a toplevel statement"
782 let invalid_constructor_method_call =
783 "Method call following immediate constructor call requires parentheses around constructor call."
785 let invalid_foreach_element =
786 "An arrow ('=>') or right parenthesis (')') is expected here."
788 let invalid_scope_resolution_qualifier =
789 "Only classnames and variables are allowed before '::'."
791 let invalid_variable_name =
792 "A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores"
794 let invalid_reference = "Only variables can be used as references"
796 let invalid_variable_variable = "Variable Variables are not legal"
798 let function_modifier s =
799 Printf.sprintf "Top-level function cannot have modifier '%s'" s
801 let invalid_yield =
802 "Yield can only appear as a statement or on the right of an assignment"
804 let invalid_yield_from =
805 "`yield from` can only appear as a statement, after `return`, or on the right of an assignment"
807 let invalid_class_in_collection_initializer =
808 "Cannot use collection initialization for non-collection class."
810 let invalid_brace_kind_in_collection_initializer =
811 "Initializers of 'vec', 'dict' and 'keyset' should use '[...]' instead of '{...}'."
813 let nested_ternary =
814 "Nested ternary expressions inside ternary expressions are ambiguous. Please add parentheses"
816 let alternate_control_flow =
817 "Alternate control flow syntax is not allowed in Hack files"
819 let execution_operator = "The execution operator is not allowed in Hack files"
821 let goto = "The `goto` operator is not allowed in Hack files"
823 let goto_label =
824 "Labels are used only for `goto`, which is not allowed in Hack files"
826 let invalid_octal_integer = "Invalid octal integers"
828 let prefixed_invalid_string_kind =
829 "Only double-quoted strings may be prefixed."
831 let non_re_prefix = "Only `re`-prefixed strings allowed."
833 let collection_intrinsic_generic =
834 "Cannot initialize collection builtins with type parameters"
836 let collection_intrinsic_many_typeargs =
837 "Collection expression must have less than three type arguments"
839 let invalid_hack_mode =
840 "Incorrect comment; possible values include strict, partial, or empty"
842 let pair_initializer_needed = "Initializer needed for Pair object"
844 let pair_initializer_arity = "Pair objects must have exactly 2 elements"
846 let nested_unary_reference = "References cannot be followed by unary operators"
848 let toplevel_statements =
849 "Toplevel statements are not allowed. Use __EntryPoint attribute instead"
851 let invalid_reified =
852 "Reify keyword can only appear at function or class type parameter position"
854 let reified_in_invalid_classish s =
855 "Invalid to use a reified type within " ^ s ^ "'s type parameters"
857 let shadowing_reified = "You may not shadow a reified parameter"
859 let static_property_in_reified_class =
860 "You may not use static properties in a class with reified type parameters"
862 let cls_reified_generic_in_static_method =
863 "You may not use reified generics of the class in a static method"
865 let static_method_reified_obj_creation =
866 "You may not use object creation for potentially reified self or parent from a static method"
868 let non_invariant_reified_generic =
869 "Reified generics cannot be covariant or contravariant"
871 let no_generics_on_constructors =
872 "Generic type parameters are not allowed on constructors. Consider adding a type parameter to the class"
874 let no_type_parameters_on_dynamic_method_calls =
875 "Generics type parameters are disallowed on dynamic method calls"
877 let dollar_unary = "The dollar sign ('$') cannot be used as a unary operator"
879 let decl_outside_global_scope =
880 "Declarations are not supported outside global scope"
882 let experimental_in_codegen_without_hacksperimental =
883 "Experimental mode files are not allowed during codegen unless the hacksperimental flag is set"
885 let expected_simple_offset_expression =
886 "A simple offset expression is expected here"
888 let illegal_interpolated_brace_with_embedded_dollar_expression =
889 "The only legal expressions inside a {$...}-expression embedded in a string are "
890 ^ "variables, function calls, subscript expressions, and member access expressions"
892 let type_alias_to_type_constant =
893 "Type aliases to type constants are not supported"
895 let interface_with_memoize = "Memoize is not allowed on interface methods"
897 let xhp_class_attribute_type_constant =
898 "Type constants are not allowed on xhp class attributes"
900 let inline_function_def =
901 "Inline function definitions are not supported in Hack"
903 let lowering_parsing_error text syntax =
904 "Encountered unexpected text '" ^ text ^ "', was expecting a " ^ syntax ^ "."
906 let multiple_reactivity_annotations =
907 "Only one of following annotations is allowed: __Rx, __RxShallow, __RxLocal, __NonRx."
909 let functions_cannot_implement_reactive =
910 "__OnlyRxIfImpl annotations are only valid on class methods."
912 let missing_reactivity_for_condition =
913 "__OnlyRxIfImpl and __AtMostRxAsArgs annotations cannot "
914 ^ "be used without __Rx, __RxShallow, or __RxLocal."
916 let misplaced_owned_mutable =
917 "__OwnedMutable annotation can only be placed on parameters."
919 let conflicting_mutable_and_owned_mutable_attributes =
920 "Parameter cannot have both __Mutable and __OwnedMutable annotations."
922 let conflicting_mutable_and_maybe_mutable_attributes =
923 "Parameter cannot have both __Mutable and __MaybeMutable annotations."
925 let conflicting_owned_mutable_and_maybe_mutable_attributes =
926 "Parameter cannot have both __OwnedMutable and __MaybeMutable annotations."
928 let mutably_owned_attribute_on_non_rx_function =
929 "__OwnedMutable annotated parameters are only allowed in reactive functions."
931 let invalid_non_rx_argument_for_lambda =
932 "Invalid argument list for __NonRx attribute that is placed on anonymous function. Argument list for __NonRx attribute that is used in this position should be empty."
934 let invalid_non_rx_argument_for_declaration =
935 "Invalid argument list for __NonRx attribute that is placed on a declaration of function or method. Argument list for __NonRx attribute that is used in this position should contain only one string literal value."
937 let nested_concurrent_blocks = "Concurrent blocks cannot be nested."
939 let fewer_than_two_statements_in_concurrent_block =
940 "Expected 2 or more statements in concurrent block. Concurrent wrapping "
941 ^ "nothing or a single statement is not useful or already implied."
943 let invalid_syntax_concurrent_block =
944 "Concurrent block must contain a compound statement of two or "
945 ^ "more expression statements, IE concurrent { <expr>; <expr>; }."
947 let statement_without_await_in_concurrent_block =
948 "Statement without an await in a concurrent block"
950 let concurrent_is_disabled = "Concurrent is disabled"
952 let static_closures_are_disabled = "Static closures are not supported in Hack"
954 let halt_compiler_is_disabled = "__halt_compiler() is not supported in Hack"
956 let invalid_await_position =
957 "Await cannot be used as an expression in this "
958 ^ "location because it's conditionally executed."
960 let invalid_await_position_dependent =
961 "Await cannot be used as an expression inside another await expression. "
962 ^ "Pull the inner await out into it's own statement."
964 let misplaced_reactivity_annotation =
965 "Reactive annotations are not allowed on classes, interfaces or traits."
967 let mutability_annotation_on_constructor =
968 "__Mutable, __MaybeMutable, and __MutableReturn annotations are not allowed on constructors."
970 let mutability_annotation_on_static_method =
971 "__Mutable and __MaybeMutable annotations are not allowed on static methods."
973 let mutability_annotation_on_inout_parameter =
974 "__Mutable, __MaybeMutable and __OwnedMutable annotations are not allowed on inout parameters."
976 let mutable_parameter_in_memoize_function ~is_this =
977 "Memoized functions cannot have mutable "
979 if is_this then
980 "$this."
981 else
982 "parameters."
984 let mutable_return_in_memoize_function =
985 "Memoized functions cannot return mutable objects."
987 let vararg_and_mutable =
988 "__Mutable, __OwnedMutable and __MaybeMutable annotations cannot be used with variadic parameters."
990 let expected_user_attribute = "A user attribute is expected here."
992 let tparams_in_tconst =
993 "Type parameters are not allowed on class type constants"
995 let targs_not_allowed = "Type arguments are not allowed in this position"
997 let reified_attribute =
998 "__Reified and __HasReifiedParent attributes may not be provided by the user"
1000 let lval_as_expression =
1001 "Assignments can no longer be used as expressions. Pull the assignment out into a separate statement."
1003 let pocket_universe_final_expected = "The 'final' keyword is expected here."
1005 let pocket_universe_enum_expected = "The 'enum' keyword is expected here."
1007 let pocket_universe_invalid_field = "Invalid pocket universe field syntax."
1009 let type_keyword = "The 'type' keyword is expected here."
1011 let non_public_const_in_interface =
1012 "Constants inside of interfaces must have 'public' visibility."
1014 let elt_abstract_private elt = "Cannot declare abstract " ^ elt ^ " private."
1016 let const_has_multiple_visibilities =
1017 "A constant cannot have multiple visibility modifiers."
1019 let const_has_duplicate_modifiers =
1020 "A constant cannot have duplicate modifiers."
1022 let only_soft_allowed = "Only the __Soft attribute is allowed here."
1024 let soft_no_arguments = "The __Soft attribute does not take arguments."
1026 let no_legacy_soft_typehints =
1027 "The @ syntax for soft typehints is not allowed. Use the __Soft attribute instead."
1029 let static_const = "Cannot declare constants static."
1031 let outside_dollar_str_interp =
1032 "The ${x} syntax is disallowed in Hack. Use {$x} instead."
1034 let no_const_interfaces_traits_enums =
1035 "Interfaces, traits and enums may not be declared __Const"
1037 let no_const_late_init_props = "__Const properties may not also be __LateInit"
1039 let no_const_static_props = "Static properties may not be __Const"
1041 let no_const_abstract_final_class =
1042 "Cannot apply __Const attribute to an abstract final class"
1044 let no_legacy_attribute_syntax =
1045 "The <<...>> syntax for user attributes is not allowed. Use the @ syntax instead."
1047 let no_silence = "The error suppression operator @ is not allowed"
1049 let declared_final elt = elt ^ " cannot be declared final."
1051 let const_mutation = "Cannot mutate a class constant"
1053 let no_attributes_on_variadic_parameter =
1054 "Attributes on variadic parameters are not allowed"