Skip to content

Commit

Permalink
Fix hackfmt for trait conflict resolution
Browse files Browse the repository at this point in the history
Summary:
Trait conflict resolution raised fatal errors, this commit fixes it.
Update FFP spec to reflect the different AST nodes for alias and conflict resolution, also fix a typo.

Differential Revision: D7568874

fbshipit-source-id: 8be4817860130933f827aac1788077a4d75f60fa
  • Loading branch information
Fangyi Zhou authored and hhvm-bot committed Apr 13, 2018
1 parent cbac5c4 commit 8fdf57a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
13 changes: 7 additions & 6 deletions hphp/hack/src/hackfmt/hack_format.ml
Expand Up @@ -500,8 +500,9 @@ let rec t (env: Env.t) (node: Syntax.t) : Doc.t =
Space;
t env kw;
Space;
t env removed_names;
Newline;
WithRule (Rule.Parental, Nest [
handle_possible_list env ~before_each:space_split removed_names;
]);
]
| Syntax.TraitUseAliasItem {
trait_use_alias_item_aliasing_name = aliasing_name;
Expand All @@ -516,7 +517,6 @@ let rec t (env: Env.t) (node: Syntax.t) : Doc.t =
t env visibility;
Space;
t env aliased_name;
Newline;
]
| Syntax.TraitUseConflictResolution {
trait_use_conflict_resolution_keyword = kw;
Expand All @@ -529,11 +529,12 @@ let rec t (env: Env.t) (node: Syntax.t) : Doc.t =
WithRule (Rule.Parental, Nest [
handle_possible_list env ~before_each:space_split elements;
]);
Space;
t env lb;
Newline;
WithRule (Rule.Parental, Nest [
handle_possible_list env ~before_each:space_split clauses;
]);
Nest [
handle_possible_list env ~before_each:newline clauses;
];
Newline;
t env rb;
]
Expand Down
10 changes: 8 additions & 2 deletions hphp/hack/src/parser/full_fidelity_declaration_parser.ml
Expand Up @@ -1040,7 +1040,7 @@ module WithExpressionAndStatementAndTypeParser
parse_property_declaration
parser attribute_spec modifiers ~contains_abstract

and parse_trait_use_precendence_item parser name =
and parse_trait_use_precedence_item parser name =
let (parser, keyword) = assert_token parser Insteadof in
let (parser, removed_names) =
parse_trait_name_list
Expand Down Expand Up @@ -1071,7 +1071,7 @@ module WithExpressionAndStatementAndTypeParser
if (peek_token_kind parser) = As then
parse_trait_use_alias_item parser name
else
parse_trait_use_precendence_item parser name
parse_trait_use_precedence_item parser name

(* SPEC:
trait-use-conflict-resolution:
Expand All @@ -1082,9 +1082,15 @@ module WithExpressionAndStatementAndTypeParser
trait-use-conflict-resolution-item trait-use-conflict-resolution-list
trait-use-conflict-resolution-item:
trait-use-alias-item
trait-use-precedence-item
trait-use-alias-item:
trait-use-conflict-resolution-item-name as name;
trait-use-conflict-resolution-item-name as visibility-modifier name;
trait-use-conflict-resolution-item-name as visibility-modifier;
trait-use-precedence-item:
scope-resolution-expression insteadof trait-name-list
trait-use-conflict-resolution-item-name:
Expand Down
@@ -0,0 +1,7 @@
<?hh

class Foo {
use Bar,Baz,Quz{
Bar::bar insteadof Baz;Baz::baz insteadof Bar,Quz;Quz::quz as quz;
}
}
@@ -0,0 +1,9 @@
<?hh

class Foo {
use Bar, Baz, Quz {
Bar::bar insteadof Baz;
Baz::baz insteadof Bar, Quz;
Quz::quz as quz;
}
}

0 comments on commit 8fdf57a

Please sign in to comment.