1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #4611 - flag invalid attribute arguments correctly

This commit is contained in:
Matt Brown 2020-11-22 00:44:44 -05:00 committed by Daniil Gentili
parent dc9a2a48e9
commit 763eff2e8b
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 32 additions and 13 deletions

View File

@ -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
);

View File

@ -159,6 +159,23 @@ class AttributeTest extends TestCase
false,
'8.0'
],
'invalidArgument' => [
'<?php
#[Attribute]
class Foo
{
public function __construct(int $i)
{
}
}
#[Foo("foo")]
class Bar{}',
'error_message' => 'InvalidScalarArgument',
[],
false,
'8.0'
],
'classAttributeUsedOnFunction' => [
'<?php
namespace Foo;