diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php index 8b3f8de7a7a..303caa17ce1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/VariableFetchAnalyzer.php @@ -541,18 +541,28 @@ public static function getGlobalType(string $var_id, int $codebase_analysis_php_ if ($var_id === '$argv') { // only in CLI, null otherwise - return new Union([ + $argv_nullable = new Union([ new TNonEmptyList(Type::getString()), new TNull() ]); + // use TNull explicitly instead of this + // as it will cause weird errors due to ignore_nullable_issues true + // e.g. InvalidPropertyAssignmentValue + // $this->argv 'list' cannot be assigned type 'non-empty-list' + // $argv_nullable->possibly_undefined = true; + $argv_nullable->ignore_nullable_issues = true; + return $argv_nullable; } if ($var_id === '$argc') { // only in CLI, null otherwise - return new Union([ + $argc_nullable = new Union([ new TIntRange(1, null), new TNull() ]); + // $argc_nullable->possibly_undefined = true; + $argc_nullable->ignore_nullable_issues = true; + return $argc_nullable; } if (!self::isSuperGlobal($var_id)) { diff --git a/tests/Internal/CliUtilsTest.php b/tests/Internal/CliUtilsTest.php index a2bfe9cb6fc..928eb0152f1 100644 --- a/tests/Internal/CliUtilsTest.php +++ b/tests/Internal/CliUtilsTest.php @@ -12,14 +12,14 @@ class CliUtilsTest extends TestCase { /** - * @var array + * @var list */ private $argv = []; protected function setUp(): void { global $argv; - $this->argv = $argv ?? []; + $this->argv = $argv; } protected function tearDown(): void