Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistency for empty reconciliations #7663

Merged
merged 1 commit into from Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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