1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-29 20:28:59 +01:00

Add special TypeDoesNotContainNull issue as distinct from TypeDoesNotContainType

This commit is contained in:
Matt Brown 2017-04-06 15:36:22 -04:00
parent cb3f6b14ba
commit da19b55db1
5 changed files with 34 additions and 12 deletions

View File

@ -157,6 +157,7 @@
<xs:element name="TooFewArguments" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TooManyArguments" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TypeCoercion" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TypeDoesNotContainNull" type="IssueHandlerType" minOccurs="0" />
<xs:element name="TypeDoesNotContainType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UndefinedClass" type="IssueHandlerType" minOccurs="0" />
<xs:element name="UndefinedConstant" type="IssueHandlerType" minOccurs="0" />

View File

@ -7,6 +7,7 @@ use Psalm\Checker\Statements\ExpressionChecker;
use Psalm\Checker\TypeChecker;
use Psalm\Clause;
use Psalm\CodeLocation;
use Psalm\Issue\TypeDoesNotContainNull;
use Psalm\Issue\TypeDoesNotContainType;
use Psalm\IssueBuffer;
use Psalm\StatementsSource;
@ -134,7 +135,7 @@ class AssertionFinder
$source->getFileChecker()
)) {
if (IssueBuffer::accepts(
new TypeDoesNotContainType(
new TypeDoesNotContainNull(
$var_type . ' does not contain ' . $null_type,
new CodeLocation($source, $conditional)
),

View File

@ -5,6 +5,7 @@ use PhpParser;
use Psalm\Checker\Statements\ExpressionChecker;
use Psalm\CodeLocation;
use Psalm\Issue\FailedTypeResolution;
use Psalm\Issue\TypeDoesNotContainNull;
use Psalm\Issue\TypeDoesNotContainType;
use Psalm\IssueBuffer;
use Psalm\StatementsSource;
@ -367,15 +368,28 @@ class TypeChecker
}
if (!$has_match) {
if (IssueBuffer::accepts(
new TypeDoesNotContainType(
'Cannot resolve types for ' . $key . ' - ' . $existing_var_type .
' does not contain ' . $new_type,
$code_location
),
$suppressed_issues
)) {
// fall through
if ($new_var_type === 'null') {
if (IssueBuffer::accepts(
new TypeDoesNotContainNull(
'Cannot resolve types for ' . $key . ' - ' . $existing_var_type .
' does not contain null',
$code_location
),
$suppressed_issues
)) {
// fall through
}
} else {
if (IssueBuffer::accepts(
new TypeDoesNotContainType(
'Cannot resolve types for ' . $key . ' - ' . $existing_var_type .
' does not contain ' . $new_type,
$code_location
),
$suppressed_issues
)) {
// fall through
}
}
$failed_reconciliation = true;

View File

@ -0,0 +1,6 @@
<?php
namespace Psalm\Issue;
class TypeDoesNotContainNull extends CodeError
{
}

View File

@ -366,7 +366,7 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage TypeDoesNotContainType
* @expectedExceptionMessage TypeDoesNotContainNull
* @return void
*/
public function testMakeNonNullableNull()
@ -437,7 +437,7 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage TypeDoesNotContainType
* @expectedExceptionMessage TypeDoesNotContainNull
* @return void
*/
public function testStringIsNotNull()