Skip to content

Commit

Permalink
Merge pull request #7663 from orklah/never2
Browse files Browse the repository at this point in the history
Consistency for empty reconciliations
  • Loading branch information
orklah committed Feb 13, 2022
2 parents 56504b8 + cf25363 commit 8a49cac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
27 changes: 19 additions & 8 deletions src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Expand Up @@ -39,6 +39,7 @@
use Psalm\Type\Atomic\TCallableString;
use Psalm\Type\Atomic\TClassConstant;
use Psalm\Type\Atomic\TClassString;
use Psalm\Type\Atomic\TEmptyMixed;
use Psalm\Type\Atomic\TFloat;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Atomic\TInt;
Expand Down Expand Up @@ -806,7 +807,9 @@ private static function reconcileHasMethod(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -899,7 +902,7 @@ private static function reconcileString(
$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

Expand Down Expand Up @@ -995,7 +998,7 @@ private static function reconcileInt(
$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

Expand Down Expand Up @@ -1471,7 +1474,9 @@ private static function reconcileCountable(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

return $intersection;
Expand Down Expand Up @@ -2325,7 +2334,9 @@ private static function reconcileCallable(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down Expand Up @@ -2544,7 +2555,7 @@ private static function reconcileClassConstant(

if ($matched_class_constant_types === []) {
$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;
return Type::getMixed();
return Type::getNever();
}

return TypeCombiner::combine($matched_class_constant_types, $codebase);
Expand Down
48 changes: 36 additions & 12 deletions src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php
Expand Up @@ -494,7 +494,9 @@ private static function reconcileBool(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = 2;

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

if (!$did_remove_type) {
Expand Down Expand Up @@ -974,7 +982,9 @@ private static function reconcileScalar(

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

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

$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

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

/**
Expand Down

0 comments on commit 8a49cac

Please sign in to comment.