diff --git a/src/Psl/Internal/Loader.php b/src/Psl/Internal/Loader.php index 3ddf2f36..a2310df0 100644 --- a/src/Psl/Internal/Loader.php +++ b/src/Psl/Internal/Loader.php @@ -699,7 +699,7 @@ final class Loader 'Psl\\Type\\Internal\\IterableType' => 'Psl/Type/Internal/IterableType.php', 'Psl\\Type\\Internal\\MixedType' => 'Psl/Type/Internal/MixedType.php', 'Psl\\Type\\Internal\\NullType' => 'Psl/Type/Internal/NullType.php', - 'Psl\\Type\\Internal\\NonNullType' => 'Psl/Type/Internal/NonNullType.php', + 'Psl\\Type\\NonNullType' => 'Psl/Type/Internal/NonNullType.php', 'Psl\\Type\\Internal\\NullableType' => 'Psl/Type/Internal/NullableType.php', 'Psl\\Type\\Internal\\OptionalType' => 'Psl/Type/Internal/OptionalType.php', 'Psl\\Type\\Internal\\PositiveIntType' => 'Psl/Type/Internal/PositiveIntType.php', diff --git a/src/Psl/Type/Internal/NonNullType.php b/src/Psl/Type/NonNullType.php similarity index 86% rename from src/Psl/Type/Internal/NonNullType.php rename to src/Psl/Type/NonNullType.php index 3fc8a645..2864cc05 100644 --- a/src/Psl/Type/Internal/NonNullType.php +++ b/src/Psl/Type/NonNullType.php @@ -2,18 +2,19 @@ declare(strict_types=1); -namespace Psl\Type\Internal; +namespace Psl\Type; use Psl\Type; use Psl\Type\Exception\AssertException; use Psl\Type\Exception\CoercionException; /** + * This type is not marked as internal, cause the class is being leaked by the nonnull() function. + * This is necessary to get coerce and assert narrow down the type without psalm having a TNonNull type. + * * @ara-extends Type\Type * * @extends Type\Type - * - * @internal */ final readonly class NonNullType extends Type\Type { diff --git a/src/Psl/Type/nonnull.php b/src/Psl/Type/nonnull.php index 73f21159..e3afb3e0 100644 --- a/src/Psl/Type/nonnull.php +++ b/src/Psl/Type/nonnull.php @@ -4,21 +4,19 @@ namespace Psl\Type; -use Psl\Type\Internal\NonNullType; - /** * @psalm-pure * * @psalm-suppress ImpureStaticVariable - The $instance is always the same and is considered pure. * - * @ara-return TypeInterface + * @ara-return NonNullType * * @return NonNullType */ -function nonnull(): TypeInterface +function nonnull(): NonNullType { - /** @var Internal\NonNullType $instance */ - static $instance = new Internal\NonNullType(); + /** @var NonNullType $instance */ + static $instance = new NonNullType(); return $instance; }