mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Do not add callable
as a native property type
It's invalid in all PHP versions: https://3v4l.org/bXWo2 Also see php.net/manual/en/language.types.declarations.php#language.types.declarations.base.function Fixes vimeo/psalm#10650
This commit is contained in:
parent
59df6a728f
commit
e8b47f7d42
@ -1649,7 +1649,9 @@ final class ClassAnalyzer extends ClassLikeAnalyzer
|
|||||||
|
|
||||||
$allow_native_type = !$docblock_only
|
$allow_native_type = !$docblock_only
|
||||||
&& $codebase->analysis_php_version_id >= 7_04_00
|
&& $codebase->analysis_php_version_id >= 7_04_00
|
||||||
&& $codebase->allow_backwards_incompatible_changes;
|
&& $codebase->allow_backwards_incompatible_changes
|
||||||
|
&& !$inferred_type->hasCallableType() // PHP does not support callable properties
|
||||||
|
;
|
||||||
|
|
||||||
$manipulator->setType(
|
$manipulator->setType(
|
||||||
$allow_native_type
|
$allow_native_type
|
||||||
|
@ -294,6 +294,42 @@ class MissingPropertyTypeTest extends FileManipulationTestCase
|
|||||||
'issues_to_fix' => ['MissingPropertyType'],
|
'issues_to_fix' => ['MissingPropertyType'],
|
||||||
'safe_types' => true,
|
'safe_types' => true,
|
||||||
],
|
],
|
||||||
|
'doNotAddCallablePropertyTypes' => [
|
||||||
|
'input' => <<<'PHP'
|
||||||
|
<?php
|
||||||
|
class A {
|
||||||
|
public $u;
|
||||||
|
public $v;
|
||||||
|
|
||||||
|
public function __construct(?callable $u, callable $v) {
|
||||||
|
$this->u = $u;
|
||||||
|
$this->v = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PHP,
|
||||||
|
'output' => <<<'PHP'
|
||||||
|
<?php
|
||||||
|
class A {
|
||||||
|
/**
|
||||||
|
* @var callable|null
|
||||||
|
*/
|
||||||
|
public $u;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var callable
|
||||||
|
*/
|
||||||
|
public $v;
|
||||||
|
|
||||||
|
public function __construct(?callable $u, callable $v) {
|
||||||
|
$this->u = $u;
|
||||||
|
$this->v = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PHP,
|
||||||
|
'php_version' => '7.4',
|
||||||
|
'issues_to_fix' => ['MissingPropertyType'],
|
||||||
|
'safe_types' => true,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user