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

Reflection-based TypeResolver #66

Draft
wants to merge 1 commit into
base: 0.4.x
Choose a base branch
from
Draft

Reflection-based TypeResolver #66

wants to merge 1 commit into from

Conversation

vudaltsov
Copy link
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