Skip to content

Commit de71cec

Browse files
WizKidmeta-codesync[bot]
authored andcommitted
Fix hackc crash when using locals in constants
Reviewed By: vassilmladenov Differential Revision: D95073805 fbshipit-source-id: cd325b2dc98dc8771200b3d1be94a6d3f3f04147
1 parent 090d464 commit de71cec

File tree

4 files changed

+14
-22
lines changed

4 files changed

+14
-22
lines changed

hphp/hack/src/parser/rust_parser_errors.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4737,7 +4737,12 @@ impl<'a, State: 'a + Clone> ParserErrors<'a, State> {
47374737
.for_each(|x| self_.check_constant_expression(x, static_allowed))
47384738
};
47394739
match &node.children {
4740-
Missing | QualifiedName(_) | LiteralExpression(_) => {}
4740+
Missing | QualifiedName(_) => {}
4741+
LiteralExpression(y) => {
4742+
if let SyntaxList(_) = &y.expression.children {
4743+
default(self)
4744+
}
4745+
}
47414746
Token(token) => {
47424747
if !is_namey(self, token) {
47434748
default(self)
@@ -4799,20 +4804,7 @@ impl<'a, State: 'a + Clone> ParserErrors<'a, State> {
47994804
self.check_constant_expression(&x.consequence, static_allowed);
48004805
self.check_constant_expression(&x.alternative, static_allowed);
48014806
}
4802-
SimpleInitializer(x) => {
4803-
if let LiteralExpression(y) = &x.value.children {
4804-
if let SyntaxList(_) = &y.expression.children {
4805-
self.errors.push(make_error_from_node(
4806-
node,
4807-
errors::invalid_constant_initializer,
4808-
))
4809-
}
4810-
self.check_constant_expression(&x.value, static_allowed)
4811-
} else {
4812-
self.check_constant_expression(&x.value, static_allowed)
4813-
}
4814-
}
4815-
4807+
SimpleInitializer(x) => self.check_constant_expression(&x.value, static_allowed),
48164808
ParenthesizedExpression(x) => {
48174809
self.check_constant_expression(&x.expression, static_allowed)
48184810
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(6,20)-(6,31) Expected constant expression for initializer
2-
(7,19)-(7,30) Expected constant expression for initializer
3-
(9,33)-(9,44) Expected constant expression for initializer
1+
(6,22)-(6,31) Expected constant expression for initializer
2+
(7,21)-(7,30) Expected constant expression for initializer
3+
(9,35)-(9,44) Expected constant expression for initializer
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
(6,20)-(6,31) Expected constant expression for initializer
2-
(7,19)-(7,30) Expected constant expression for initializer
3-
(10,21)-(10,32) Expected constant expression for initializer
1+
(6,22)-(6,31) Expected constant expression for initializer
2+
(7,21)-(7,30) Expected constant expression for initializer
3+
(10,23)-(10,32) Expected constant expression for initializer
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ERROR: File "global_const18.php", line 3, characters 15-20:
1+
ERROR: File "global_const18.php", line 3, characters 17-20:
22
Expected constant expression for initializer (Parsing[1002])
33
ERROR: File "global_const18.php", line 3, characters 17-20:
44
Illegal constant value (Naming[2023])

0 commit comments

Comments
 (0)