module RubyBreaker::Typing

This module contains subtyping logic used in RubyBreaker. See rubytype.rb for logic related to subclassing which is directly related to pure Ruby types.

Public Class Methods

subtype_rel?(lhs, rhs) click to toggle source

This method determines if one type is a subtype of another. This check is for RubyBreaker defined types. See TypeDefs module for more detail.

lhs

The allegedly “subtype”

rhs

The allegedly “supertype”

# File lib/rubybreaker/typing/subtyping.rb, line 441
def self.subtype_rel?(lhs, rhs)

  # Don't even bother if they are same object or syntactically
  # equivalent. NOTE: would this really help improve performance???
  return true if (lhs.equal?(rhs) || lhs.eql?(rhs))

  # Break down the cases by what LHS is.
  is_subtype = false
  if lhs.instance_of?(NilType)
    is_subtype = rhs.instance_of?(NilType)
  elsif lhs.instance_of?(AnyType)
    is_subtype = true 
  elsif lhs.instance_of?(SelfType)
    is_subtype = self.self_subtype_rel?(lhs,rhs)
  elsif lhs.instance_of?(NominalType)
    is_subtype = self.nominal_subtype_rel?(lhs,rhs)
  elsif lhs.instance_of?(FusionType)
    is_subtype = self.fusion_subtype_rel?(lhs,rhs)
  elsif lhs.instance_of?(DuckType)
    is_subtype = self.duck_subtype_rel?(lhs,rhs)
  elsif lhs.instance_of?(MethodType)
    is_subtype = self.method_subtype_rel?(lhs,rhs)
  elsif lhs.instance_of?(OrType)
    is_subtype = self.or_subtype_rel?(lhs,rhs)
  elsif lhs.instance_of?(BlockType)
    is_subtype = self.proc_subtype_rel?(lhs,rhs)
  elsif lhs.instance_of?(MethodListType)
    is_subtype = self.method_subtype_rel?(lhs,rhs)
  end
  return is_subtype
end