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

TASK: Reform of the TypeInterface #23

Open
grebaldi opened this issue Jun 7, 2023 · 0 comments
Open

TASK: Reform of the TypeInterface #23

grebaldi opened this issue Jun 7, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@grebaldi
Copy link
Member

grebaldi commented Jun 7, 2023

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
@grebaldi grebaldi added the enhancement New feature or request label Jun 7, 2023
@grebaldi grebaldi changed the title Reform of the TypeInterface TASK: Reform of the TypeInterface Jul 24, 2023
@grebaldi grebaldi added this to the v1.0 milestone Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant