lib/rbs/definition.rb in rbs-0.20.1 vs lib/rbs/definition.rb in rbs-1.0.0.pre

- old
+ new

@@ -32,10 +32,24 @@ @member = member @defined_in = defined_in @implemented_in = implemented_in end + def ==(other) + other.is_a?(TypeDef) && + other.type == type && + other.member == member && + other.defined_in == defined_in && + other.implemented_in == implemented_in + end + + alias eql? == + + def hash + self.class.hash ^ type.hash ^ member.hash ^ defined_in.hash ^ implemented_in.hash + end + def comment member.comment end def annotations @@ -68,10 +82,25 @@ @accessibility = accessibility @extra_annotations = annotations @alias_of = alias_of end + def ==(other) + other.is_a?(Method) && + other.super_method == super_method && + other.defs == defs && + other.accessibility == accessibility && + other.annotations == annotations && + other.alias_of == alias_of + end + + alias eql? == + + def hash + self.class.hash ^ super_method.hash ^ defs.hash ^ accessibility.hash ^ annotations.hash ^ alias_of.hash + end + def defined_in @defined_in ||= begin last_def = defs.last or raise last_def.defined_in end @@ -135,12 +164,47 @@ ) end end module Ancestor - Instance = _ = Struct.new(:name, :args, keyword_init: true) - Singleton = _ = Struct.new(:name, keyword_init: true) + class Instance + attr_reader :name, :args, :source + + def initialize(name:, args:, source:) + @name = name + @args = args + @source = source + end + + def ==(other) + other.is_a?(Instance) && other.name == name && other.args == args + end + + alias eql? == + + def hash + self.class.hash ^ name.hash ^ args.hash + end + end + + class Singleton + attr_reader :name + + def initialize(name:) + @name = name + end + + def ==(other) + other.is_a?(Singleton) && other.name == name + end + + alias eql? == + + def hash + self.class.hash ^ name.hash + end + end end class InstanceAncestors attr_reader :type_name attr_reader :params @@ -168,11 +232,12 @@ if ancestor.args.empty? ancestor else Ancestor::Instance.new( name: ancestor.name, - args: ancestor.args.map {|type| type.sub(subst) } + args: ancestor.args.map {|type| type.sub(subst) }, + source: ancestor.source ) end when Ancestor::Singleton ancestor end @@ -231,9 +296,11 @@ def interface? case en = entry when Environment::SingleEntry en.decl.is_a?(AST::Declarations::Interface) + else + false end end def class_type? self_type.is_a?(Types::ClassSingleton)