Skip to content

Commit

Permalink
Merge pull request vimeo#10388 from kkmuffme/temp-empty-reconciliatio…
Browse files Browse the repository at this point in the history
…ns-failing-tests

Fix redundant condition mixed type escape hatch & loose comparison int type shouldnt be mixed
  • Loading branch information
orklah authored Nov 21, 2023
2 parents 5f0332b + 0d7c5a2 commit 07acefd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 102 deletions.
4 changes: 1 addition & 3 deletions src/Psalm/Internal/Type/NegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ public static function reconcile(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

return $existing_var_type;
Expand Down
73 changes: 21 additions & 52 deletions src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use Psalm\Type\Atomic\TCallableString;
use Psalm\Type\Atomic\TClassConstant;
use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TEmptyMixed;
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\TGenericObject;
Expand Down Expand Up @@ -976,9 +975,7 @@ private static function reconcileHasMethod(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

return $existing_var_type->from_docblock
? new Union([new TEmptyMixed()])
: Type::getNever();
return Type::getNever();
}

/**
Expand Down Expand Up @@ -1040,6 +1037,10 @@ private static function reconcileString(
$string_types[] = $type;
}

$redundant = false;
} elseif ($type instanceof TInt && $assertion instanceof IsLooselyEqual) {
// don't change the type of an int for non-strict comparisons
$string_types[] = $type;
$redundant = false;
} else {
$redundant = false;
Expand Down Expand Up @@ -1067,9 +1068,7 @@ private static function reconcileString(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

return $existing_var_type->from_docblock
? new Union([new TEmptyMixed()])
: Type::getNever();
return Type::getNever();
}

/**
Expand Down Expand Up @@ -1161,9 +1160,7 @@ private static function reconcileInt(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

return $existing_var_type->from_docblock
? new Union([new TEmptyMixed()])
: Type::getNever();
return Type::getNever();
}

/**
Expand Down Expand Up @@ -1240,9 +1237,7 @@ private static function reconcileBool(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1325,9 +1320,7 @@ private static function reconcileFalse(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1410,9 +1403,7 @@ private static function reconcileTrue(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1485,9 +1476,7 @@ private static function reconcileScalar(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1578,9 +1567,7 @@ private static function reconcileNumeric(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1698,9 +1685,7 @@ private static function reconcileObject(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1756,9 +1741,7 @@ private static function reconcileResource(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1828,9 +1811,7 @@ private static function reconcileCountable(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1891,9 +1872,7 @@ private static function reconcileIterable(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1935,9 +1914,7 @@ private static function reconcileInArray(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

return $intersection;
Expand Down Expand Up @@ -2256,9 +2233,7 @@ private static function reconcileTraversable(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -2371,9 +2346,7 @@ private static function reconcileArray(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -2481,9 +2454,7 @@ private static function reconcileList(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -2721,9 +2692,7 @@ private static function reconcileCallable(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down
56 changes: 14 additions & 42 deletions src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ public static function reconcile(
}
}

return $existing_var_type->from_docblock
? Type::getNull()
: Type::getNever();
return Type::getNever();
}

return Type::getNull();
Expand Down Expand Up @@ -507,9 +505,7 @@ private static function reconcileBool(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -703,9 +699,7 @@ private static function reconcileNull(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -785,9 +779,7 @@ private static function reconcileFalse(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -867,9 +859,7 @@ private static function reconcileTrue(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -924,9 +914,7 @@ private static function reconcileFalsyOrEmpty(

$failed_reconciliation = 2;

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

if ($redundant) {
Expand Down Expand Up @@ -1139,9 +1127,7 @@ private static function reconcileScalar(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1240,9 +1226,7 @@ private static function reconcileObject(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1336,9 +1320,7 @@ private static function reconcileNumeric(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1438,9 +1420,7 @@ private static function reconcileInt(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1535,9 +1515,7 @@ private static function reconcileFloat(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1641,9 +1619,7 @@ private static function reconcileString(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1746,9 +1722,7 @@ private static function reconcileArray(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -1818,9 +1792,7 @@ private static function reconcileResource(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/TypeReconciliation/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function foo($length) {
}
}',
'assertions' => [],
'ignored_issues' => ['DocblockTypeContradiction'],
'ignored_issues' => ['DocblockTypeContradiction', 'TypeDoesNotContainType'],
],
'notInstanceof' => [
'code' => '<?php
Expand Down Expand Up @@ -1350,7 +1350,6 @@ function takes_string(string $string) : void {}
function takes_int(int $int) : void {}
if ($int == $string) {
/** @psalm-suppress MixedArgument */
takes_int($int);
}',
],
Expand Down
Loading

0 comments on commit 07acefd

Please sign in to comment.