1
0
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:
Matthew Brown 2017-04-15 12:44:38 -04:00
parent bdfe2396ad
commit eebaf5795d
2 changed files with 32 additions and 1 deletions

View File

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

View File

@ -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
*/