mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Allow adding Closure
as a native property type
This commit is contained in:
parent
e8b47f7d42
commit
b2a2cd7884
@ -1650,7 +1650,9 @@ final class ClassAnalyzer extends ClassLikeAnalyzer
|
||||
$allow_native_type = !$docblock_only
|
||||
&& $codebase->analysis_php_version_id >= 7_04_00
|
||||
&& $codebase->allow_backwards_incompatible_changes
|
||||
&& !$inferred_type->hasCallableType() // PHP does not support callable properties
|
||||
// PHP does not support callable properties, but does allow Closure properties
|
||||
// hasCallableType() treats Closure as a callable, but getCallableTypes() does not
|
||||
&& $inferred_type->getCallableTypes() === []
|
||||
;
|
||||
|
||||
$manipulator->setType(
|
||||
|
@ -50,7 +50,8 @@ final class TClosure extends TNamedObject
|
||||
|
||||
public function canBeFullyExpressedInPhp(int $analysis_php_version_id): bool
|
||||
{
|
||||
return false;
|
||||
// it can, if it's just 'Closure'
|
||||
return $this->params === null && $this->return_type === null && $this->is_pure === null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -330,6 +330,29 @@ class MissingPropertyTypeTest extends FileManipulationTestCase
|
||||
'issues_to_fix' => ['MissingPropertyType'],
|
||||
'safe_types' => true,
|
||||
],
|
||||
'addClosurePropertyType' => [
|
||||
'input' => <<<'PHP'
|
||||
<?php
|
||||
class A {
|
||||
public $u;
|
||||
public function __construct(Closure $u) {
|
||||
$this->u = $u;
|
||||
}
|
||||
}
|
||||
PHP,
|
||||
'output' => <<<'PHP'
|
||||
<?php
|
||||
class A {
|
||||
public Closure $u;
|
||||
public function __construct(Closure $u) {
|
||||
$this->u = $u;
|
||||
}
|
||||
}
|
||||
PHP,
|
||||
'php_version' => '7.4',
|
||||
'issues_to_fix' => ['MissingPropertyType'],
|
||||
'safe_types' => true,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user