Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve from_docblock in TypeCombiner #8999

Merged
merged 6 commits into from Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Psalm/Type/MutableUnion.php
Expand Up @@ -234,7 +234,7 @@ public function setTypes(array $types): self
$this->typed_class_strings = [];
$this->checked = false;

$from_docblock = false;
$from_docblock = $this->from_docblock;
$keyed_types = [];

foreach ($types as $type) {
Expand Down
23 changes: 22 additions & 1 deletion tests/TypeReconciliation/RedundantConditionTest.php
Expand Up @@ -1085,7 +1085,7 @@ function takesA(A $a): void {}
/** @psalm-suppress PossiblyNullArgument */
takesA($a);
if ($a instanceof A) {}',
'error_message' => 'RedundantCondition - src' . DIRECTORY_SEPARATOR . 'somefile.php:15',
'error_message' => 'RedundantConditionGivenDocblockType - src' . DIRECTORY_SEPARATOR . 'somefile.php:15',
],
'replaceFalseType' => [
'code' => '<?php
Expand Down Expand Up @@ -1546,6 +1546,27 @@ function f(array $p) : void {
}',
'error_message' => 'RedundantCondition',
],
'https://github.com/vimeo/psalm/issues/8932' => [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a reference is a great idea but I still would like to have some kind of title Maybe a comment in the code itself? If someday, we were to migrate from github, we could loose the meaning behind the tests completely

'code' => '<?php
/**
* @param array|null $value
* *
* * @return null
*/
function reverseTransform($value)
{
if (null === $value) {
return null;
}

if (!\is_array($value)) {
throw new \Exception("array");
}

return null;
}',
'error_message' => 'DocblockTypeContradiction',
],
];
}
}