Skip to content
Permalink
Browse files

Be more accurate when assertion is incorrect

Ref #2452
  • Loading branch information
muglug committed Dec 10, 2019
1 parent 8494f02 commit 750d4b4f4f79fdd8441dbcc2101aab4f8347a743
Showing with 33 additions and 8 deletions.
  1. +24 −8 src/Psalm/Internal/Type/AssertionReconciler.php
  2. +9 −0 tests/TypeReconciliation/ConditionalTest.php
@@ -1041,7 +1041,9 @@ private static function reconcileString(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -1100,7 +1102,9 @@ private static function reconcileBool(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -1155,7 +1159,9 @@ private static function reconcileScalar(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -1220,7 +1226,9 @@ private static function reconcileNumeric(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -1283,7 +1291,9 @@ private static function reconcileObject(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -1517,7 +1527,9 @@ private static function reconcileTraversable(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -1591,7 +1603,9 @@ private static function reconcileArray(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -1681,7 +1695,9 @@ private static function reconcileList(

$failed_reconciliation = 2;

return Type::getMixed();
return $existing_var_type->from_docblock
? Type::getMixed()
: Type::getEmpty();
}

/**
@@ -2213,6 +2213,15 @@ function foo($value) : void {
}
}'
],
'ignoreRedundantAssertion' => [
'<?php
function gimmeAString(?string $v): string {
/** @psalm-suppress TypeDoesNotContainType */
assert(is_string($v) || is_object($v));
return $v;
}'
],
];
}

0 comments on commit 750d4b4

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