diff --git a/hphp/hack/src/hhbc/emit_type_constant.ml b/hphp/hack/src/hhbc/emit_type_constant.ml index cb63b439e5b61..eafd4a01b54e4 100644 --- a/hphp/hack/src/hhbc/emit_type_constant.ml +++ b/hphp/hack/src/hhbc/emit_type_constant.ml @@ -74,14 +74,17 @@ let check_shape_key (pos, name) = then Emit_fatal.raise_fatal_parse pos "Shape key names may not start with integers" -let shape_field_name = function +let shape_field_name ~namespace = function | A.SFlit ((_, s) as id) -> check_shape_key id; s, false - | A.SFclass_const ((_, id), (_, s)) -> id ^ "::" ^ s, true + | A.SFclass_const (id, (_, s)) -> + let classname, _ = Hhbc_id.Class.elaborate_id namespace id in + let id = Hhbc_id.Class.to_raw_string classname in + id ^ "::" ^ s, true let rec shape_field_to_pair ~tparams ~namespace sf = - let name, is_class_const = shape_field_name sf.A.sf_name in + let name, is_class_const = shape_field_name ~namespace sf.A.sf_name in let is_optional = sf.A.sf_optional in let hint = sf.A.sf_hint in let class_const = diff --git a/hphp/hack/src/hhbc/hhbc_hhas.ml b/hphp/hack/src/hhbc/hhbc_hhas.ml index e8c5cfa81dc90..ce12b5e723a75 100644 --- a/hphp/hack/src/hhbc/hhbc_hhas.ml +++ b/hphp/hack/src/hhbc/hhbc_hhas.ml @@ -1761,9 +1761,9 @@ let add_typedef buf typedef = B.add_string buf " \"\"\""; B.add_string buf @@ SS.seq_to_string @@ Emit_adata.adata_to_string_seq ts; - B.add_string buf "\"\"\";\n" + B.add_string buf "\"\"\";" | None -> - B.add_string buf ";\n" + B.add_string buf ";" let add_include_region ?path ?doc_root ?search_paths ?include_roots ?(check_paths_exist=true) diff --git a/hphp/test/slow/namespace/alias/namespaced_aliases.php b/hphp/test/slow/namespace/alias/namespaced_aliases.php new file mode 100644 index 0000000000000..1c4abfebd8657 --- /dev/null +++ b/hphp/test/slow/namespace/alias/namespaced_aliases.php @@ -0,0 +1,58 @@ + string, +); + +type T = MyEnum; + +type UsesFoo = shape(Foo::VALUE => int); +type UsesBar = shape(Bar::VALUE => int); +type UsesBaz = shape(\SomeNS\Baz::VALUE => int); + +type ExplicitRelative = shape(namespace\MyEnum::FOO => int); +type ImplicitRelative = shape(MySubNS\MyEnum::VALUE => int); + +var_dump(type_structure(MyShape::class)); +var_dump(type_structure(T::class)); +var_dump(type_structure(UsesFoo::class)); +var_dump(type_structure(UsesBar::class)); +var_dump(type_structure(UsesBaz::class)); +var_dump(type_structure(ExplicitRelative::class)); +var_dump(type_structure(ImplicitRelative::class)); + +} diff --git a/hphp/test/slow/namespace/alias/namespaced_aliases.php.expect b/hphp/test/slow/namespace/alias/namespaced_aliases.php.expect new file mode 100644 index 0000000000000..74d60497bbcf6 --- /dev/null +++ b/hphp/test/slow/namespace/alias/namespaced_aliases.php.expect @@ -0,0 +1,92 @@ +array(3) { + ["kind"]=> + int(14) + ["fields"]=> + array(1) { + ["Herp"]=> + array(1) { + ["kind"]=> + int(4) + } + } + ["alias"]=> + string(12) "MyNS\MyShape" +} +array(3) { + ["kind"]=> + int(18) + ["classname"]=> + string(11) "MyNS\MyEnum" + ["alias"]=> + string(6) "MyNS\T" +} +array(3) { + ["kind"]=> + int(14) + ["fields"]=> + array(1) { + ["SomeNS\Foo"]=> + array(1) { + ["kind"]=> + int(1) + } + } + ["alias"]=> + string(12) "MyNS\UsesFoo" +} +array(3) { + ["kind"]=> + int(14) + ["fields"]=> + array(1) { + ["SomeNS\Bar"]=> + array(1) { + ["kind"]=> + int(1) + } + } + ["alias"]=> + string(12) "MyNS\UsesBar" +} +array(3) { + ["kind"]=> + int(14) + ["fields"]=> + array(1) { + ["SomeNS\Baz"]=> + array(1) { + ["kind"]=> + int(1) + } + } + ["alias"]=> + string(12) "MyNS\UsesBaz" +} +array(3) { + ["kind"]=> + int(14) + ["fields"]=> + array(1) { + ["Herp"]=> + array(1) { + ["kind"]=> + int(1) + } + } + ["alias"]=> + string(21) "MyNS\ExplicitRelative" +} +array(3) { + ["kind"]=> + int(14) + ["fields"]=> + array(1) { + ["Herp"]=> + array(1) { + ["kind"]=> + int(1) + } + } + ["alias"]=> + string(21) "MyNS\ImplicitRelative" +}