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:
parent
dc9a2a48e9
commit
763eff2e8b
@ -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
|
||||
);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user