mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix regression dealing with union types from docblocks
This commit is contained in:
parent
bdfe2396ad
commit
eebaf5795d
@ -1170,6 +1170,8 @@ class TypeChecker
|
||||
return $union;
|
||||
}
|
||||
|
||||
$from_docblock = $union->from_docblock;
|
||||
|
||||
$unique_types = [];
|
||||
|
||||
foreach ($union->types as $type_part) {
|
||||
@ -1202,6 +1204,10 @@ class TypeChecker
|
||||
throw new \UnexpectedValueException('There must be more than one unique type');
|
||||
}
|
||||
|
||||
return new Type\Union($unique_types);
|
||||
$unique_type = new Type\Union($unique_types);
|
||||
|
||||
$unique_type->from_docblock = $from_docblock;
|
||||
|
||||
return $unique_type;
|
||||
}
|
||||
}
|
||||
|
@ -986,6 +986,31 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testTypeReconciliationAfterIfAndReturn()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
/**
|
||||
* @param string|int $a
|
||||
* @return string|int
|
||||
*/
|
||||
function foo($a) {
|
||||
if (is_string($a)) {
|
||||
return $a;
|
||||
} elseif (is_int($a)) {
|
||||
return $a;
|
||||
}
|
||||
|
||||
throw new \LogicException("Runtime error");
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user