Skip to content

Commit

Permalink
Fix enum parsing when the syntax is "enum foo:string {}" without spac…
Browse files Browse the repository at this point in the history
…e between name and type, fixes #10498
  • Loading branch information
Seldaek committed Feb 2, 2022
1 parent 2da8d88 commit db8ea45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/Composer/Autoload/ClassMapGenerator.php
Expand Up @@ -272,11 +272,18 @@ private static function findClasses($path)
// This is an XHP class, https://github.com/facebook/xhp
$name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
} elseif ($matches['type'][$i] === 'enum') {
// In Hack, something like:
// something like:
// enum Foo: int { HERP = '123'; }
// The regex above captures the colon, which isn't part of
// 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, '\\');
}
Expand Down
@@ -1,6 +1,6 @@
<?php

enum RolesBackedEnum: string {
enum RolesBackedEnum:string {
case Admin = 'Administrator';
case Guest = 'Guest';
case Moderator = 'Moderator';
Expand Down

0 comments on commit db8ea45

Please sign in to comment.