1
0
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:
Matthew Brown 2017-12-03 01:24:47 -05:00
parent f8f67d4d86
commit a47675250a
2 changed files with 24 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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) {}',
],
];
}