Page MenuHomePhabricator

PhutilTypeSpec fails with classes
Closed, ResolvedPublic

Description

PhutilTypeSpec claims to support "AnyClassOrInterfaceName", however the followiing code raises an exception:

PhutilTypeSpec::newFromString('stdClass')->check(new stdClass());

The exception message is EXCEPTION (PhutilTypeCheckException): Parameter has invalid type. Expected type 'stdClass', got type 'stdClass'.. It seems to me that this is not the correct behaviour.

Furthermore, it would be great if PhutilTypeSpec supported subclasses so that, for example, list<Exception> could be used to match array(new Exception(), new RuntimeException(), new LogicException().'

I'm happy to fix this bug and add in subclass support (seems fairly easy), but first wanted to clarify whether this is the intended behaviour (in which case the documentation is incorrect).

Event Timeline

joshuaspence assigned this task to epriestley.
joshuaspence raised the priority of this task from to Needs Triage.
joshuaspence updated the task description. (Show Details)
joshuaspence added a project: libphutil.
joshuaspence added a subscriber: joshuaspence.