mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
parent
4e17585093
commit
d7561919b2
@ -865,6 +865,11 @@ class NewAnalyzer extends CallAnalyzer
|
||||
&& $stmt_class_type->ignore_nullable_issues
|
||||
) {
|
||||
// do nothing
|
||||
} elseif ($lhs_type_part instanceof TObject
|
||||
|| $lhs_type_part instanceof TNamedObject
|
||||
) {
|
||||
$new_type = Type::combineUnionTypes($new_type, new Union([$lhs_type_part]));
|
||||
continue;
|
||||
} elseif (IssueBuffer::accepts(
|
||||
new UndefinedClass(
|
||||
'Type ' . $lhs_type_part . ' cannot be called as a class',
|
||||
|
@ -795,6 +795,62 @@ class ClassTest extends TestCase
|
||||
abstract class C implements I {}
|
||||
',
|
||||
],
|
||||
'newOnNamedObject' => [
|
||||
'code' => '<?php
|
||||
$o = new stdClass;
|
||||
$o2 = new $o;
|
||||
',
|
||||
'assertions' => [
|
||||
'$o2===' => 'stdClass',
|
||||
],
|
||||
],
|
||||
'newOnObject' => [
|
||||
'code' => '<?php
|
||||
/** @var object $o */;
|
||||
$o2 = new $o;
|
||||
',
|
||||
'assertions' => [
|
||||
'$o2===' => 'object',
|
||||
],
|
||||
],
|
||||
'newOnObjectOfAnonymousClass' => [
|
||||
'code' => '<?php
|
||||
function f(): object {
|
||||
$o = new class {};
|
||||
return new $o;
|
||||
}
|
||||
',
|
||||
],
|
||||
'newOnObjectOfAnonymousExtendingNamed' => [
|
||||
'code' => '<?php
|
||||
function f(): Exception {
|
||||
$o = new class extends Exception {};
|
||||
return new $o;
|
||||
}
|
||||
',
|
||||
],
|
||||
'newOnObjectOfAnonymousClassImplementingNamed' => [
|
||||
'code' => '<?php
|
||||
interface I {}
|
||||
function f(): I {
|
||||
$o = new class implements I {};
|
||||
return new $o;
|
||||
}
|
||||
',
|
||||
],
|
||||
'throwAnonymousObjects' => [
|
||||
'code' => '<?php
|
||||
throw new class extends Exception {};
|
||||
',
|
||||
],
|
||||
'throwTheResultOfNewOnAnAnonymousClass' => [
|
||||
'code' => '<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
$test = new class extends \Exception { };
|
||||
throw new $test();
|
||||
'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user