1
0
Fork 0

Fix enum parsing when the syntax is "enum foo:string {}" without space between name and type, fixes #10498

pull/10512/head
Jordi Boggiano 2022-02-02 17:48:45 +01:00
parent 2da8d886cc
commit db8ea45295
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 10 additions and 3 deletions

View File

@ -272,11 +272,18 @@ class ClassMapGenerator
// This is an XHP class, https://github.com/facebook/xhp // This is an XHP class, https://github.com/facebook/xhp
$name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1); $name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
} elseif ($matches['type'][$i] === 'enum') { } elseif ($matches['type'][$i] === 'enum') {
// In Hack, something like: // something like:
// enum Foo: int { HERP = '123'; } // enum Foo: int { HERP = '123'; }
// The regex above captures the colon, which isn't part of // The regex above captures the colon, which isn't part of
// the class name. // the class name.
$name = rtrim($name, ':'); // or:
// enum Foo:int { HERP = '123'; }
// The regex above captures the colon and type, which isn't part of
// the class name.
$colonPos = strrpos($name, ':');
if (false !== $colonPos) {
$name = substr($name, 0, $colonPos);
}
} }
$classes[] = ltrim($namespace . $name, '\\'); $classes[] = ltrim($namespace . $name, '\\');
} }