Skip to content

Commit

Permalink
Fix return type when rejecting constant arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
axlon committed Sep 26, 2024
1 parent 4e3fa4e commit 7689d95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Type/PhpOption/TypeUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public static function forShallowComparison(Type $type): Type
return $traverse($type);
}

return $type->isConstantScalarValue()->yes() ? $type : new NeverType();
if ($type->isConstantScalarValue()->yes() || $type->isConstantArray()->yes()) {
return $type;
}

return new NeverType();
});
}
}
7 changes: 7 additions & 0 deletions tests/Type/PhpOption/data/option-reject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
/**
* @var \PhpOption\Option<string|null> $option
*/
assertType('PhpOption\Option<non-empty-string|null>', $option->reject(''));
assertType('PhpOption\Option<string|null>', $option->reject('string'));
assertType('PhpOption\Option<string|null>', $option->reject(123));
assertType('PhpOption\Option<string>', $option->reject(null));

/**
* @var \PhpOption\Option<array<string>> $option
*/
assertType('PhpOption\Option<non-empty-array<string>>', $option->reject([]));
assertType('PhpOption\Option<array<string>>', $option->reject(''));

0 comments on commit 7689d95

Please sign in to comment.