Fix regression on defaults for abstract type constantsnightly-2019.06.21
authorVassil Mladenov <[email protected]>
Fri, 21 Jun 2019 00:26:16 +0000 (20 17:26 -0700)
committerHhvm Bot <[email protected]>
Fri, 21 Jun 2019 00:31:17 +0000 (20 17:31 -0700)
Summary: This was a regression from the move to codegen off the Aast.

Reviewed By: oulgen

Differential Revision: D15925292

fbshipit-source-id: 04a128eccd0a6388385550ae7c57d10d2e240dad

hphp/hack/src/hhbc/emit_class.ml
hphp/test/slow/class_type_constant/default.php [new file with mode: 0644]
hphp/test/slow/class_type_constant/default.php.expect [new file with mode: 0644]

index 4b5a749..7018b7c 100644 (file)
@@ -119,9 +119,12 @@ let from_constant env (_hint, name, const_init) =
 
 let from_type_constant namespace tc =
   let type_constant_name = snd tc.A.c_tconst_name in
-  match tc.A.c_tconst_type with
-  | None -> Hhas_type_constant.make type_constant_name None
-  | Some init ->
+  match tc.A.c_tconst_abstract, tc.A.c_tconst_type with
+  | A.TCAbstract None, _
+  | (A.TCPartiallyAbstract | A.TCConcrete), None ->
+    Hhas_type_constant.make type_constant_name None
+  | A.TCAbstract (Some init), _
+  | (A.TCPartiallyAbstract | A.TCConcrete), Some init ->
     (* TODO: Deal with the constraint *)
     let type_constant_initializer =
       (* Type constants do not take type vars hence tparams:[] *)
diff --git a/hphp/test/slow/class_type_constant/default.php b/hphp/test/slow/class_type_constant/default.php
new file mode 100644 (file)
index 0000000..2b4641e
--- /dev/null
@@ -0,0 +1,17 @@
+<?hh // strict
+// Copyright 2004-present Facebook. All Rights Reserved.
+
+abstract class C {
+  abstract const type T = arraykey;
+}
+
+class D extends C {
+
+}
+
+class E extends C {
+  const type T = int;
+}
+
+var_dump(type_structure(D::class, 'T'));
+var_dump(type_structure(E::class, 'T'));
diff --git a/hphp/test/slow/class_type_constant/default.php.expect b/hphp/test/slow/class_type_constant/default.php.expect
new file mode 100644 (file)
index 0000000..6f9cf43
--- /dev/null
@@ -0,0 +1,8 @@
+array(1) {
+  ["kind"]=>
+  int(7)
+}
+array(1) {
+  ["kind"]=>
+  int(1)
+}
\ No newline at end of file