mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix invalid InvalidParamDefault error when comparing to false
This commit is contained in:
parent
3510757d89
commit
27a018095b
@ -347,7 +347,9 @@ class StatementsChecker extends SourceChecker implements StatementsSource
|
||||
public static function getSimpleType(PhpParser\Node\Expr $stmt)
|
||||
{
|
||||
if ($stmt instanceof PhpParser\Node\Expr\ConstFetch) {
|
||||
if (strtolower($stmt->name->parts[0]) === 'false' || strtolower($stmt->name->parts[0]) === 'true') {
|
||||
if (strtolower($stmt->name->parts[0]) === 'false') {
|
||||
return Type::getFalse();
|
||||
} elseif (strtolower($stmt->name->parts[0]) === 'true') {
|
||||
return Type::getBool();
|
||||
} elseif (strtolower($stmt->name->parts[0]) === 'null') {
|
||||
return Type::getNull();
|
||||
|
@ -177,6 +177,60 @@ class FunctionCallTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidParamDefault
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidParamDefault()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function f(int $p = false) {}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context();
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidParamDefault
|
||||
* @return void
|
||||
*/
|
||||
public function testInvalidDocblockParamDefault()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
/**
|
||||
* @param int $p
|
||||
* @return void
|
||||
*/
|
||||
function f($p = false) {}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context();
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testValidDocblockParamDefault()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
/**
|
||||
* @param int|false $p
|
||||
* @return void
|
||||
*/
|
||||
function f($p = false) {}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context();
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
@ -211,6 +211,28 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testUnionContains()
|
||||
{
|
||||
$this->assertTrue(
|
||||
TypeChecker::isContainedBy(
|
||||
Type::parseString('string'),
|
||||
Type::parseString('string|false'),
|
||||
$this->file_checker
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
TypeChecker::isContainedBy(
|
||||
Type::parseString('false'),
|
||||
Type::parseString('string|false'),
|
||||
$this->file_checker
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user