mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Fix #5049 - assertion of !empty
on bool makes true
This commit is contained in:
parent
5e75140ca5
commit
0c52f528bd
@ -586,6 +586,12 @@ class SimpleNegatedAssertionReconciler extends Reconciler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($existing_var_type->hasBool()) {
|
||||||
|
$existing_var_type->removeType('bool');
|
||||||
|
|
||||||
|
$existing_var_type->addType(new Type\Atomic\TTrue);
|
||||||
|
}
|
||||||
|
|
||||||
self::removeFalsyNegatedLiteralTypes(
|
self::removeFalsyNegatedLiteralTypes(
|
||||||
$existing_var_type,
|
$existing_var_type,
|
||||||
$did_remove_type
|
$did_remove_type
|
||||||
|
@ -1674,6 +1674,20 @@ class AssertAnnotationTest extends TestCase
|
|||||||
}',
|
}',
|
||||||
'error_message' => 'InvalidDocblock',
|
'error_message' => 'InvalidDocblock',
|
||||||
],
|
],
|
||||||
|
'assertNotEmptyOnBool' => [
|
||||||
|
'<?php
|
||||||
|
/**
|
||||||
|
* @param mixed $value
|
||||||
|
* @psalm-assert !empty $value
|
||||||
|
*/
|
||||||
|
function assertNotEmpty($value) : void {}
|
||||||
|
|
||||||
|
function foo(bool $bar) : void {
|
||||||
|
assertNotEmpty($bar);
|
||||||
|
if ($bar) {}
|
||||||
|
}',
|
||||||
|
'error_message' => 'RedundantConditionGivenDocblockType',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,7 @@ class ReconcilerTest extends \Psalm\Tests\TestCase
|
|||||||
'iterableWithParamsToTraversableWithParams' => ['Traversable<int, string>', '!array', 'iterable<int, string>'],
|
'iterableWithParamsToTraversableWithParams' => ['Traversable<int, string>', '!array', 'iterable<int, string>'],
|
||||||
'iterableAndObject' => ['Traversable<int, string>', 'object', 'iterable<int, string>'],
|
'iterableAndObject' => ['Traversable<int, string>', 'object', 'iterable<int, string>'],
|
||||||
'iterableAndNotObject' => ['array<int, string>', '!object', 'iterable<int, string>'],
|
'iterableAndNotObject' => ['array<int, string>', '!object', 'iterable<int, string>'],
|
||||||
|
'boolNotEmptyIsTrue' => ['true', '!empty', 'bool'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user