Skip to content

TASK: Reform of the TypeInterface #23

@grebaldi

Description

@grebaldi

The TypeInterface currently looks like this:

interface TypeInterface
{
    public function is(TypeInterface $other): bool;
}

The method is is fairly ambiguous, since it could mean "equivalence" (= $other is actually the exact same type) or "implication" (= $other is a sub-type of $this).

So, I'd suggest to change the interface thusly:

interface TypeInterface
{
    public function equals(TypeInterface $other): bool;
    public function isSuperTypeOf(TypeInterface $other): bool;
}

An alternative name for isSuperTypeOf would be implies. The interface could also reverse the direction of query and have a method isSubTypeOf (or: isImpliedBy). Personally, I'm indifferent to either of these, but would strictly opt for having only one of those methods.

The rules for the built-in types in regards to isSuperTypeOf should be as follows:

Built-in Type isSuperTypeOf($other) when...
BooleanType equals($other)
ComponentType equals($other)
EnumStaticType equals($other)
EnumType equals($other)
NumberType equals($other)
SlotType equals($other) or $other is one of: StringType, ComponentType
StringType equals($other)
StructType equals($other)
UnionType equals($other) or $other is UnionType with fewer, but compatible members, or $other is any member type of this union

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions