From 763eff2e8b4583d2e4ad6a6fa6165f7b84a9d402 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 22 Nov 2020 00:44:44 -0500 Subject: [PATCH] Fix #4611 - flag invalid attribute arguments correctly --- .../Internal/Analyzer/AttributeAnalyzer.php | 28 ++++++++++--------- tests/AttributeTest.php | 17 +++++++++++ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/AttributeAnalyzer.php b/src/Psalm/Internal/Analyzer/AttributeAnalyzer.php index d32524cc5..95cf8b0bc 100644 --- a/src/Psalm/Internal/Analyzer/AttributeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/AttributeAnalyzer.php @@ -63,25 +63,27 @@ class AttributeAnalyzer return; } + $type_expr = \Psalm\Internal\Stubs\Generator\StubsGenerator::getExpressionFromType( + $type + ); + + $arg_attributes = [ + 'startFilePos' => $storage_arg->location->raw_file_start, + 'endFilePos' => $storage_arg->location->raw_file_end, + 'startLine' => $storage_arg->location->raw_line_number + ]; + + $type_expr->setAttributes($arg_attributes); + $node_args[] = new PhpParser\Node\Arg( - \Psalm\Internal\Stubs\Generator\StubsGenerator::getExpressionFromType( - $type - ), + $type_expr, false, false, - [ - 'startFilePos' => $storage_arg->location->raw_file_start, - 'endFilePos' => $storage_arg->location->raw_file_end, - 'startLine' => $storage_arg->location->raw_line_number - ], + $arg_attributes, $storage_arg->name ? new PhpParser\Node\Identifier( $storage_arg->name, - [ - 'startFilePos' => $storage_arg->location->raw_file_start, - 'endFilePos' => $storage_arg->location->raw_file_end, - 'startLine' => $storage_arg->location->raw_line_number - ] + $arg_attributes ) : null ); diff --git a/tests/AttributeTest.php b/tests/AttributeTest.php index c68d0e9b7..be08806bd 100644 --- a/tests/AttributeTest.php +++ b/tests/AttributeTest.php @@ -159,6 +159,23 @@ class AttributeTest extends TestCase false, '8.0' ], + 'invalidArgument' => [ + ' 'InvalidScalarArgument', + [], + false, + '8.0' + ], 'classAttributeUsedOnFunction' => [ '