rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Constraints on variables

Open grncdr opened this issue 5 years ago • 0 comments

It seems that currently the grammar only supports type constraints in the case of module declarations. It would be very useful to be able to constrain type variables, e.g. to require a particular interface.

For example:

interface _Comparable
  def <=>: (untyped other) -> Integer | nil
end

class Heap[Elem : _Comparable]
  def add: (Elem) -> void
end

grncdr avatar Dec 31 '20 14:12 grncdr