public interface SubtypeOperator
Represents the subtype operation over types. This can be though of as similar
to the subset operator commonly found in set theory. Following this view,
types are seen as sets containing their possible values as elements. For
example, the type int would correspond to the set of all
possible integer values. Then, one type is a subtype another if the set it
corresponds to is a subset of the other's corresponding set.
| Modifier and Type | Interface and Description |
|---|---|
static class |
SubtypeOperator.Result |
| Modifier and Type | Method and Description |
|---|---|
SubtypeOperator.Result |
isSubtype(WyalFile.Type lhs,
WyalFile.Type rhs)
Determine whether the
rhs type is a subtype of the
lhs (denoted lhs :> rhs). |
SubtypeOperator.Result isSubtype(WyalFile.Type lhs, WyalFile.Type rhs) throws wybs.lang.NameResolver.ResolutionError
Determine whether the rhs type is a subtype of the
lhs (denoted lhs :> rhs). In the presence of
type invariants, this operation is undecidable. Therefore, a
three-valued logic is employed. Either it was concluded that the
subtype relation definitely holds, or that it definitely does
not hold that it is unknown whether it holds or not.
For example, int|null :> int definitely holds. Likewise,
int :> int|null definitely does not hold. However, whether
or not nat :> pos holds depends on the type invariants given
for nat and pos which this operator cannot
reason about. Observe that, in some cases, we do get effective reasoning
about types with invariants. For example, null|nat :> nat
will be determined to definitely hold, despite the fact that
nat has a type invariant.
Depending on the exact language of types involved, this can be a surprisingly complex operation. For example, in the presence of union, intersection and negation types, the subtype algorithm is surprisingly intricate.
lhs - The candidate "supertype". That is, lhs's raw type may be a
supertype of rhs's raw type.rhs - The candidate "subtype". That is, rhs's raw type may be a
subtype of lhs's raw type.wybs.lang.NameResolver.ResolutionError - Occurs when a nominal type is encountered whose name cannot
be resolved properly. For example, it resolves to more than
one possible matching declaration, or it cannot be resolved
to a corresponding type declaration.Copyright © 2017. All rights reserved.