mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Set that a type is from docblock when substituting in docblock atomic type
This commit is contained in:
parent
f8f67d4d86
commit
a47675250a
@ -213,6 +213,11 @@ class Context
|
||||
// also never allow ourselves to remove all types from a union
|
||||
if ((string)$old_type !== (string)$new_type && ($new_type || count($context_type->types) > 1)) {
|
||||
$context_type->substitute($old_type, $new_type);
|
||||
|
||||
if ($new_type && $new_type->from_docblock) {
|
||||
$context_type->setFromDocblock();
|
||||
}
|
||||
|
||||
$updated_vars[$var] = true;
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,25 @@ class RedundantConditionTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'noRedundantConditionTypeReplacementWithDocblock' => [
|
||||
'<?php
|
||||
class A {}
|
||||
|
||||
/**
|
||||
* @return A
|
||||
*/
|
||||
function getA() {
|
||||
return new A();
|
||||
}
|
||||
|
||||
$maybe_a = rand(0, 1) ? new A : null;
|
||||
|
||||
if ($maybe_a === null) {
|
||||
$maybe_a = getA();
|
||||
}
|
||||
|
||||
if ($maybe_a === null) {}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user