1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Don't convert standalone false/true to bool in combineTypes (#396)

Fixes #392
This commit is contained in:
Tyson Andre 2017-12-15 13:36:42 -08:00 committed by Matthew Brown
parent e2e86beee7
commit d0fe5e3127
3 changed files with 39 additions and 5 deletions

View File

@ -527,10 +527,6 @@ abstract class Type
}
if (count($types) === 1) {
if ($types[0] instanceof TBool) {
$types[0] = new TBool;
}
return new Union([$types[0]]);
}

View File

@ -174,11 +174,17 @@ class TypeCombinationTest extends TestCase
],
],
'onlyFalse' => [
'bool',
'false',
[
'false',
],
],
'onlyTrue' => [
'true',
[
'true',
],
],
'falseFalseDestruction' => [
'bool',
[

View File

@ -927,6 +927,24 @@ class TypeTest extends TestCase
}',
'assertions' => [],
],
'trueFalseTest' => [
'<?php
class A {
/** @return true */
public function returnsTrue() { return true; }
/** @return false */
public function returnsFalse() { return false; }
/** @return bool */
public function returnsBool() {
if (rand() % 2 > 0) {
return true;
}
return false;
}
}',
],
];
}
@ -1269,6 +1287,20 @@ class TypeTest extends TestCase
}',
'error_message' => 'PossiblyUndefinedMethod',
],
'notTrueTest' => [
'<?php
/** @return true */
function returnsTrue() { return rand() % 2 > 0; }
',
'error_message' => 'InvalidReturnStatement',
],
'notFalseTest' => [
'<?php
/** @return false */
function returnsFalse() { return rand() % 2 > 0; }
',
'error_message' => 'InvalidReturnStatement',
],
];
}
}