class RBS::TypeAliasRegularity

TypeAliasRegularity validates if a type alias is regular or not.

Generic and recursive type alias cannot be polymorphic in their definitions.

type foo[T] = Integer
            | foo[T]?     # Allowed. The type argument of `foo` doesn't change.

type bar[T] = Integer
            | foo[T]
            | foo[Array[T]]  # Allowed. There are two type arguments `T` and `Array[T]` of `foo`, but it's not definition of `foo`.

type baz[T] = Integer
            | baz[Array[T]]  # Error. Recursive definition of `baz` has different type argument from the definition.

The nonregular? method can be used to test if given type name is regular or not.

validator = RBS::TypeAliasRegularity.validate(env: env)

validator.nonregular?(TypeName.parse("::foo"))    # => nil
validator.nonregular?(TypeName.parse("::bar"))    # => nil
validator.nonregular?(TypeName.parse("::baz"))    # => TypeAliasRegularity::Diagnostic

A special case is when the type argument is untyped.

type foo[T] = Integer | foo[untyped]    # This is allowed.