Skip to content

Commit

Permalink
Fix #2789 - Numeric should not be a reserved class name
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 12, 2020
1 parent a23dd9f commit 07a53f6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Expand Up @@ -119,7 +119,7 @@ public function analyze(

if ($class->name
&& (preg_match(
'/(^|\\\)(int|float|bool|string|void|null|false|true|object|numeric|mixed)$/i',
'/(^|\\\)(int|float|bool|string|void|null|false|true|object|mixed)$/i',
$fq_class_name
) || strtolower($fq_class_name) === 'resource')
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php
Expand Up @@ -240,7 +240,7 @@ public static function checkFullyQualifiedClassLikeName(
}

if (preg_match(
'/(^|\\\)(int|float|bool|string|void|null|false|true|object|numeric|mixed)$/i',
'/(^|\\\)(int|float|bool|string|void|null|false|true|object|mixed)$/i',
$fq_class_name
) || strtolower($fq_class_name) === 'resource'
) {
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Type.php
Expand Up @@ -206,7 +206,6 @@ private static function fixScalarTerms(
case 'iterable':
case 'array':
case 'object':
case 'numeric':
case 'true':
case 'false':
case 'null':
Expand Down
25 changes: 25 additions & 0 deletions tests/ClassTest.php
Expand Up @@ -466,6 +466,31 @@ class OldAChild extends OldA {}
action(new OldA());
action(new OldAChild());'
],
'resourceAndNumericSoftlyReserved' => [
'<?php
namespace Foo {
class Resource {}
class Numeric {}
}
namespace Bar {
use \Foo\Resource;
use \Foo\Numeric;
new \Foo\Resource();
new \Foo\Numeric();
new Resource();
new Numeric();
/**
* @param Resource $r
* @param Numeric $n
* @return void
*/
function foo(Resource $r, Numeric $n) : void {}
}'
],
];
}

Expand Down

0 comments on commit 07a53f6

Please sign in to comment.