Skip to content
Permalink
Browse files

Fix #2035 - warn about erroneous casting

  • Loading branch information...
muglug committed Aug 20, 2019
1 parent a3e9dec commit d0f277a168a10a551d628c75b4a3e034a543e774
@@ -442,6 +442,23 @@ function (\Psalm\Internal\Clause $c) use ($mixed_var_ids) {
$t_if_context->inside_isset = false;
if (isset($stmt->left->inferredType)
&& !$stmt->left->inferredType->isMixed()
&& !$stmt->left->inferredType->isNullable()
) {
if (!$stmt->left->inferredType->from_docblock) {
if (IssueBuffer::accepts(
new \Psalm\Issue\TypeDoesNotContainType(
$stmt->left->inferredType->getId() . ' is always defined and non-null',
new CodeLocation($statements_analyzer, $stmt->left)
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
}
}
foreach ($t_if_context->vars_in_scope as $var_id => $type) {
if (isset($context->vars_in_scope[$var_id])) {
$context->vars_in_scope[$var_id] = Type::combineUnionTypes($context->vars_in_scope[$var_id], $type);
@@ -1468,6 +1468,13 @@ function render(array $data): ?Traversable {
return null;
}'
],
'nullCoalesceTypedValue' => [
'<?php
/** @param string[] $arr */
function foo(array $arr) : string {
return $arr["b"] ?? "bar";
}',
],
];
}
@@ -1752,6 +1759,13 @@ function firstChar(string $s) : string { return $s; }
if (false !== firstChar("sdf")) {}',
'error_message' => 'RedundantCondition',
],
'nullCoalesceImpossible' => [
'<?php
function foo(?string $s) : string {
return ((string) $s) ?? "bar";
}',
'error_message' => 'TypeDoesNotContainType'
],
];
}
}

0 comments on commit d0f277a

Please sign in to comment.
You can’t perform that action at this time.