mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add special TypeDoesNotContainNull issue as distinct from TypeDoesNotContainType
This commit is contained in:
parent
cb3f6b14ba
commit
da19b55db1
@ -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" />
|
||||
|
@ -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)
|
||||
),
|
||||
|
@ -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,6 +368,18 @@ class TypeChecker
|
||||
}
|
||||
|
||||
if (!$has_match) {
|
||||
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 .
|
||||
@ -377,6 +390,7 @@ class TypeChecker
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
|
||||
$failed_reconciliation = true;
|
||||
}
|
||||
|
6
src/Psalm/Issue/TypeDoesNotContainNull.php
Normal file
6
src/Psalm/Issue/TypeDoesNotContainNull.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class TypeDoesNotContainNull extends CodeError
|
||||
{
|
||||
}
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user