Skip to content

Reflection-based TypeResolver#66

Draft
vudaltsov wants to merge 1 commit into0.4.xfrom
type-resolver
Draft

Reflection-based TypeResolver#66
vudaltsov wants to merge 1 commit into0.4.xfrom
type-resolver

Conversation

@vudaltsov
Copy link
Copy Markdown
Member

@vudaltsov vudaltsov commented Aug 5, 2024

/**
 * @psalm-type A = B
 * @psalm-type B = self::MIN
 */
final class MyClass
{
    public const MIN = -100;
    public const MAX = 200;

    public const MASK_1 = 1;
    public const MASK_2 = 2;
    public const MASK_4 = 4;

    /**
     * @var int<A, self::MAX>
     */
    public int $x;

    /**
     * @var self::MASK_*
     */
    public int $mask;
}

$reflector = TyphoonReflector::build();
$class = $reflector->reflectClass(MyClass::class);

echo stringify($class->properties()['x']->type()->accept(new ExternalTypeResolver($reflector))), PHP_EOL;
// int<-100, 200>

echo stringify($class->properties()['mask']->type()->accept(new ExternalTypeResolver($reflector))), PHP_EOL;
// 1|2|4

@vudaltsov vudaltsov added this to the 0.4.x milestone Aug 5, 2024
@vudaltsov vudaltsov self-assigned this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant