rbs 0.16.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +30 -0
- data/README.md +1 -1
- data/Rakefile +12 -1
- data/core/array.rbs +1 -1
- data/core/builtin.rbs +2 -2
- data/core/dir.rbs +1 -1
- data/core/enumerable.rbs +41 -40
- data/core/enumerator.rbs +5 -5
- data/core/file.rbs +0 -4
- data/core/hash.rbs +9 -11
- data/core/io.rbs +1 -1
- data/core/object_space.rbs +98 -0
- data/core/range.rbs +1 -1
- data/core/struct.rbs +1 -1
- data/core/time.rbs +0 -12
- data/lib/rbs/ast/members.rb +9 -3
- data/lib/rbs/definition.rb +9 -4
- data/lib/rbs/definition_builder.rb +123 -71
- data/lib/rbs/environment.rb +3 -0
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/environment_walker.rb +70 -35
- data/lib/rbs/method_type.rb +1 -31
- data/lib/rbs/parser.rb +944 -879
- data/lib/rbs/parser.y +110 -63
- data/lib/rbs/prototype/rb.rb +163 -23
- data/lib/rbs/prototype/rbi.rb +5 -5
- data/lib/rbs/prototype/runtime.rb +2 -1
- data/lib/rbs/test/hook.rb +30 -17
- data/lib/rbs/test/type_check.rb +6 -1
- data/lib/rbs/types.rb +63 -6
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +9 -1
- data/schema/members.json +5 -1
- data/sig/definition.rbs +8 -3
- data/sig/definition_builder.rbs +6 -2
- data/sig/members.rbs +4 -1
- data/sig/method_types.rbs +3 -16
- data/sig/types.rbs +17 -1
- data/stdlib/csv/0/csv.rbs +3 -3
- data/stdlib/dbm/0/dbm.rbs +1 -3
- data/stdlib/monitor/0/monitor.rbs +119 -0
- data/stdlib/prime/0/prime.rbs +1 -1
- data/stdlib/set/0/set.rbs +10 -10
- data/stdlib/singleton/0/singleton.rbs +111 -0
- data/stdlib/tsort/0/cyclic.rbs +4 -0
- data/stdlib/tsort/0/interfaces.rbs +19 -0
- data/stdlib/tsort/0/tsort.rbs +371 -0
- data/stdlib/yaml/0/dbm.rbs +221 -0
- data/stdlib/yaml/0/store.rbs +53 -0
- data/steep/Gemfile.lock +12 -12
- metadata +11 -3
    
        data/core/io.rbs
    CHANGED
    
    
| @@ -0,0 +1,98 @@ | |
| 1 | 
            +
            # The ObjectSpace module contains a number of routines that interact with the
         | 
| 2 | 
            +
            # garbage collection facility and allow you to traverse all living objects with
         | 
| 3 | 
            +
            # an iterator.
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # ObjectSpace also provides support for object finalizers, procs that will be
         | 
| 6 | 
            +
            # called when a specific object is about to be destroyed by garbage collection.
         | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
            #     require 'objspace'
         | 
| 9 | 
            +
            #
         | 
| 10 | 
            +
            #     a = "A"
         | 
| 11 | 
            +
            #     b = "B"
         | 
| 12 | 
            +
            #
         | 
| 13 | 
            +
            #     ObjectSpace.define_finalizer(a, proc {|id| puts "Finalizer one on #{id}" })
         | 
| 14 | 
            +
            #     ObjectSpace.define_finalizer(b, proc {|id| puts "Finalizer two on #{id}" })
         | 
| 15 | 
            +
            #
         | 
| 16 | 
            +
            # *produces:*
         | 
| 17 | 
            +
            #
         | 
| 18 | 
            +
            #     Finalizer two on 537763470
         | 
| 19 | 
            +
            #     Finalizer one on 537763480
         | 
| 20 | 
            +
            module ObjectSpace
         | 
| 21 | 
            +
              def self._id2ref: (Integer id) -> untyped
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              # Counts all objects grouped by type.
         | 
| 24 | 
            +
              #
         | 
| 25 | 
            +
              # It returns a hash, such as:
         | 
| 26 | 
            +
              #     {
         | 
| 27 | 
            +
              #       :TOTAL=>10000,
         | 
| 28 | 
            +
              #       :FREE=>3011,
         | 
| 29 | 
            +
              #       :T_OBJECT=>6,
         | 
| 30 | 
            +
              #       :T_CLASS=>404,
         | 
| 31 | 
            +
              #       # ...
         | 
| 32 | 
            +
              #     }
         | 
| 33 | 
            +
              #
         | 
| 34 | 
            +
              # The contents of the returned hash are implementation specific. It may be
         | 
| 35 | 
            +
              # changed in future.
         | 
| 36 | 
            +
              #
         | 
| 37 | 
            +
              # The keys starting with `:T_` means live objects. For example, `:T_ARRAY` is
         | 
| 38 | 
            +
              # the number of arrays. `:FREE` means object slots which is not used now.
         | 
| 39 | 
            +
              # `:TOTAL` means sum of above.
         | 
| 40 | 
            +
              #
         | 
| 41 | 
            +
              # If the optional argument `result_hash` is given, it is overwritten and
         | 
| 42 | 
            +
              # returned. This is intended to avoid probe effect.
         | 
| 43 | 
            +
              #
         | 
| 44 | 
            +
              #     h = {}
         | 
| 45 | 
            +
              #     ObjectSpace.count_objects(h)
         | 
| 46 | 
            +
              #     puts h
         | 
| 47 | 
            +
              #     # => { :TOTAL=>10000, :T_CLASS=>158280, :T_MODULE=>20672, :T_STRING=>527249 }
         | 
| 48 | 
            +
              #
         | 
| 49 | 
            +
              # This method is only expected to work on C Ruby.
         | 
| 50 | 
            +
              #
         | 
| 51 | 
            +
              def self.count_objects: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
         | 
| 52 | 
            +
             | 
| 53 | 
            +
              # Adds *aProc* as a finalizer, to be called after *obj* was destroyed. The
         | 
| 54 | 
            +
              # object ID of the *obj* will be passed as an argument to *aProc*. If *aProc* is
         | 
| 55 | 
            +
              # a lambda or method, make sure it can be called with a single argument.
         | 
| 56 | 
            +
              #
         | 
| 57 | 
            +
              def self.define_finalizer: (untyped obj, ^(Integer id) -> void aProc) -> [ Integer, Proc ]
         | 
| 58 | 
            +
                                       | (untyped obj) { (Integer id) -> void } -> [ Integer, Proc ]
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              # Calls the block once for each living, nonimmediate object in this Ruby
         | 
| 61 | 
            +
              # process. If *module* is specified, calls the block for only those classes or
         | 
| 62 | 
            +
              # modules that match (or are a subclass of) *module*. Returns the number of
         | 
| 63 | 
            +
              # objects found. Immediate objects (`Fixnum`s, `Symbol`s `true`, `false`, and
         | 
| 64 | 
            +
              # `nil`) are never returned. In the example below, #each_object returns both the
         | 
| 65 | 
            +
              # numbers we defined and several constants defined in the Math module.
         | 
| 66 | 
            +
              #
         | 
| 67 | 
            +
              # If no block is given, an enumerator is returned instead.
         | 
| 68 | 
            +
              #
         | 
| 69 | 
            +
              #     a = 102.7
         | 
| 70 | 
            +
              #     b = 95       # Won't be returned
         | 
| 71 | 
            +
              #     c = 12345678987654321
         | 
| 72 | 
            +
              #     count = ObjectSpace.each_object(Numeric) {|x| p x }
         | 
| 73 | 
            +
              #     puts "Total count: #{count}"
         | 
| 74 | 
            +
              #
         | 
| 75 | 
            +
              # *produces:*
         | 
| 76 | 
            +
              #
         | 
| 77 | 
            +
              #     12345678987654321
         | 
| 78 | 
            +
              #     102.7
         | 
| 79 | 
            +
              #     2.71828182845905
         | 
| 80 | 
            +
              #     3.14159265358979
         | 
| 81 | 
            +
              #     2.22044604925031e-16
         | 
| 82 | 
            +
              #     1.7976931348623157e+308
         | 
| 83 | 
            +
              #     2.2250738585072e-308
         | 
| 84 | 
            +
              #     Total count: 7
         | 
| 85 | 
            +
              #
         | 
| 86 | 
            +
              def self.each_object: (?Module `module`) -> Enumerator[untyped, Integer]
         | 
| 87 | 
            +
                                  | (?Module `module`) { (untyped obj) -> void } -> Integer
         | 
| 88 | 
            +
             | 
| 89 | 
            +
              def self.garbage_collect: (?full_mark: bool, ?immediate_mark: bool, ?immediate_sweep: bool) -> void
         | 
| 90 | 
            +
             | 
| 91 | 
            +
              # Removes all finalizers for *obj*.
         | 
| 92 | 
            +
              #
         | 
| 93 | 
            +
              def self.undefine_finalizer: [X] (X obj) -> X
         | 
| 94 | 
            +
             | 
| 95 | 
            +
              private
         | 
| 96 | 
            +
             | 
| 97 | 
            +
              def garbage_collect: (?full_mark: bool, ?immediate_mark: bool, ?immediate_sweep: bool) -> void
         | 
| 98 | 
            +
            end
         | 
    
        data/core/range.rbs
    CHANGED
    
    
    
        data/core/struct.rbs
    CHANGED
    
    | @@ -27,7 +27,7 @@ | |
| 27 27 | 
             
            # struct member which is either a quoted string ( `"name"` ) or a
         | 
| 28 28 | 
             
            # [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html) ( `:name` ).
         | 
| 29 29 | 
             
            class Struct[Elem] < Object
         | 
| 30 | 
            -
              include Enumerable[Elem | 
| 30 | 
            +
              include Enumerable[Elem]
         | 
| 31 31 |  | 
| 32 32 | 
             
              type attribute_name = Symbol | String
         | 
| 33 33 |  | 
    
        data/core/time.rbs
    CHANGED
    
    | @@ -757,18 +757,6 @@ class Time < Object | |
| 757 757 | 
             
              #
         | 
| 758 758 | 
             
              def subsec: () -> Numeric
         | 
| 759 759 |  | 
| 760 | 
            -
              # Returns a new Time object, one second later than *time*. Time#succ is obsolete
         | 
| 761 | 
            -
              # since 1.9.2 for time is not a discrete value.
         | 
| 762 | 
            -
              #
         | 
| 763 | 
            -
              #     t = Time.now       #=> 2007-11-19 08:23:57 -0600
         | 
| 764 | 
            -
              #     t.succ             #=> 2007-11-19 08:23:58 -0600
         | 
| 765 | 
            -
              #
         | 
| 766 | 
            -
              # Use instead `time + 1`
         | 
| 767 | 
            -
              #
         | 
| 768 | 
            -
              #     t + 1              #=> 2007-11-19 08:23:58 -0600
         | 
| 769 | 
            -
              #
         | 
| 770 | 
            -
              def succ: () -> Time
         | 
| 771 | 
            -
             | 
| 772 760 | 
             
              # Returns `true` if *time* represents Sunday.
         | 
| 773 761 | 
             
              #
         | 
| 774 762 | 
             
              #     t = Time.local(1990, 4, 1)       #=> 1990-04-01 00:00:00 -0600
         | 
    
        data/lib/rbs/ast/members.rb
    CHANGED
    
    | @@ -216,31 +216,34 @@ module RBS | |
| 216 216 | 
             
                  module Attribute
         | 
| 217 217 | 
             
                    attr_reader :name
         | 
| 218 218 | 
             
                    attr_reader :type
         | 
| 219 | 
            +
                    attr_reader :kind
         | 
| 219 220 | 
             
                    attr_reader :ivar_name
         | 
| 220 221 | 
             
                    attr_reader :annotations
         | 
| 221 222 | 
             
                    attr_reader :location
         | 
| 222 223 | 
             
                    attr_reader :comment
         | 
| 223 224 |  | 
| 224 | 
            -
                    def initialize(name:, type:, ivar_name:, annotations:, location:, comment:)
         | 
| 225 | 
            +
                    def initialize(name:, type:, ivar_name:, kind:, annotations:, location:, comment:)
         | 
| 225 226 | 
             
                      @name = name
         | 
| 226 227 | 
             
                      @type = type
         | 
| 227 228 | 
             
                      @ivar_name = ivar_name
         | 
| 228 229 | 
             
                      @annotations = annotations
         | 
| 229 230 | 
             
                      @location = location
         | 
| 230 231 | 
             
                      @comment = comment
         | 
| 232 | 
            +
                      @kind = kind
         | 
| 231 233 | 
             
                    end
         | 
| 232 234 |  | 
| 233 235 | 
             
                    def ==(other)
         | 
| 234 236 | 
             
                      other.is_a?(self.class) &&
         | 
| 235 237 | 
             
                        other.name == name &&
         | 
| 236 238 | 
             
                        other.type == type &&
         | 
| 237 | 
            -
                        other.ivar_name == ivar_name
         | 
| 239 | 
            +
                        other.ivar_name == ivar_name &&
         | 
| 240 | 
            +
                        other.kind == kind
         | 
| 238 241 | 
             
                    end
         | 
| 239 242 |  | 
| 240 243 | 
             
                    alias eql? ==
         | 
| 241 244 |  | 
| 242 245 | 
             
                    def hash
         | 
| 243 | 
            -
                      self.class.hash ^ name.hash ^ type.hash ^ ivar_name.hash
         | 
| 246 | 
            +
                      self.class.hash ^ name.hash ^ type.hash ^ ivar_name.hash ^ kind.hash
         | 
| 244 247 | 
             
                    end
         | 
| 245 248 | 
             
                  end
         | 
| 246 249 |  | 
| @@ -253,6 +256,7 @@ module RBS | |
| 253 256 | 
             
                        name: name,
         | 
| 254 257 | 
             
                        type: type,
         | 
| 255 258 | 
             
                        ivar_name: ivar_name,
         | 
| 259 | 
            +
                        kind: kind,
         | 
| 256 260 | 
             
                        annotations: annotations,
         | 
| 257 261 | 
             
                        location: location,
         | 
| 258 262 | 
             
                        comment: comment
         | 
| @@ -269,6 +273,7 @@ module RBS | |
| 269 273 | 
             
                        name: name,
         | 
| 270 274 | 
             
                        type: type,
         | 
| 271 275 | 
             
                        ivar_name: ivar_name,
         | 
| 276 | 
            +
                        kind: kind,
         | 
| 272 277 | 
             
                        annotations: annotations,
         | 
| 273 278 | 
             
                        location: location,
         | 
| 274 279 | 
             
                        comment: comment
         | 
| @@ -285,6 +290,7 @@ module RBS | |
| 285 290 | 
             
                        name: name,
         | 
| 286 291 | 
             
                        type: type,
         | 
| 287 292 | 
             
                        ivar_name: ivar_name,
         | 
| 293 | 
            +
                        kind: kind,
         | 
| 288 294 | 
             
                        annotations: annotations,
         | 
| 289 295 | 
             
                        location: location,
         | 
| 290 296 | 
             
                        comment: comment
         | 
    
        data/lib/rbs/definition.rb
    CHANGED
    
    | @@ -60,12 +60,14 @@ module RBS | |
| 60 60 | 
             
                  attr_reader :defs
         | 
| 61 61 | 
             
                  attr_reader :accessibility
         | 
| 62 62 | 
             
                  attr_reader :extra_annotations
         | 
| 63 | 
            +
                  attr_reader :alias_of
         | 
| 63 64 |  | 
| 64 | 
            -
                  def initialize(super_method:, defs:, accessibility:, annotations: [])
         | 
| 65 | 
            +
                  def initialize(super_method:, defs:, accessibility:, annotations: [], alias_of:)
         | 
| 65 66 | 
             
                    @super_method = super_method
         | 
| 66 67 | 
             
                    @defs = defs
         | 
| 67 68 | 
             
                    @accessibility = accessibility
         | 
| 68 69 | 
             
                    @extra_annotations = annotations
         | 
| 70 | 
            +
                    @alias_of = alias_of
         | 
| 69 71 | 
             
                  end
         | 
| 70 72 |  | 
| 71 73 | 
             
                  def defined_in
         | 
| @@ -110,7 +112,8 @@ module RBS | |
| 110 112 | 
             
                    self.class.new(
         | 
| 111 113 | 
             
                      super_method: super_method&.sub(s),
         | 
| 112 114 | 
             
                      defs: defs.map {|defn| defn.update(type: defn.type.sub(s)) },
         | 
| 113 | 
            -
                      accessibility: @accessibility
         | 
| 115 | 
            +
                      accessibility: @accessibility,
         | 
| 116 | 
            +
                      alias_of: alias_of
         | 
| 114 117 | 
             
                    )
         | 
| 115 118 | 
             
                  end
         | 
| 116 119 |  | 
| @@ -118,7 +121,8 @@ module RBS | |
| 118 121 | 
             
                    self.class.new(
         | 
| 119 122 | 
             
                      super_method: super_method&.map_type(&block),
         | 
| 120 123 | 
             
                      defs: defs.map {|defn| defn.update(type: defn.type.map_type(&block)) },
         | 
| 121 | 
            -
                      accessibility: @accessibility
         | 
| 124 | 
            +
                      accessibility: @accessibility,
         | 
| 125 | 
            +
                      alias_of: alias_of
         | 
| 122 126 | 
             
                    )
         | 
| 123 127 | 
             
                  end
         | 
| 124 128 |  | 
| @@ -126,7 +130,8 @@ module RBS | |
| 126 130 | 
             
                    self.class.new(
         | 
| 127 131 | 
             
                      super_method: super_method,
         | 
| 128 132 | 
             
                      defs: defs.map {|defn| defn.update(type: yield(defn.type)) },
         | 
| 129 | 
            -
                      accessibility: @accessibility
         | 
| 133 | 
            +
                      accessibility: @accessibility,
         | 
| 134 | 
            +
                      alias_of: alias_of
         | 
| 130 135 | 
             
                    )
         | 
| 131 136 | 
             
                  end
         | 
| 132 137 | 
             
                end
         | 
| @@ -558,7 +558,7 @@ module RBS | |
| 558 558 | 
             
                        )
         | 
| 559 559 | 
             
                      end
         | 
| 560 560 |  | 
| 561 | 
            -
                      unless array.all? {|pair| pair[1] == :public}
         | 
| 561 | 
            +
                      unless array.all? {|pair| pair[1] == :public }
         | 
| 562 562 | 
             
                        raise InconsistentMethodVisibilityError.new(
         | 
| 563 563 | 
             
                          type_name: type_name,
         | 
| 564 564 | 
             
                          method_name: method_name,
         | 
| @@ -599,10 +599,15 @@ module RBS | |
| 599 599 | 
             
                  try_cache(type_name, cache: one_instance_cache) do
         | 
| 600 600 | 
             
                    entry = env.class_decls[type_name]
         | 
| 601 601 |  | 
| 602 | 
            +
                    param_names = entry.type_params.each.map(&:name)
         | 
| 602 603 | 
             
                    self_type = Types::ClassInstance.new(name: type_name,
         | 
| 603 | 
            -
                                                         args: Types::Variable.build( | 
| 604 | 
            +
                                                         args: Types::Variable.build(param_names),
         | 
| 604 605 | 
             
                                                         location: nil)
         | 
| 605 | 
            -
                    ancestors =  | 
| 606 | 
            +
                    ancestors = Definition::InstanceAncestors.new(
         | 
| 607 | 
            +
                      type_name: type_name,
         | 
| 608 | 
            +
                      params: param_names,
         | 
| 609 | 
            +
                      ancestors: [Definition::Ancestor::Instance.new(name: type_name, args: self_type.args)]
         | 
| 610 | 
            +
                    )
         | 
| 606 611 |  | 
| 607 612 | 
             
                    Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
         | 
| 608 613 | 
             
                      method_definition_members(type_name, entry, kind: :instance).each do |method_name, array|
         | 
| @@ -618,13 +623,15 @@ module RBS | |
| 618 623 | 
             
                              Definition::Method.new(
         | 
| 619 624 | 
             
                                super_method: nil,
         | 
| 620 625 | 
             
                                accessibility: visibility,
         | 
| 621 | 
            -
                                defs: method_def.defs.map {|defn| defn.update(implemented_in: type_name) }
         | 
| 626 | 
            +
                                defs: method_def.defs.map {|defn| defn.update(implemented_in: type_name) },
         | 
| 627 | 
            +
                                alias_of: nil
         | 
| 622 628 | 
             
                              )
         | 
| 623 629 | 
             
                            else
         | 
| 624 630 | 
             
                              Definition::Method.new(
         | 
| 625 631 | 
             
                                super_method: nil,
         | 
| 626 632 | 
             
                                accessibility: visibility,
         | 
| 627 | 
            -
                                defs: []
         | 
| 633 | 
            +
                                defs: [],
         | 
| 634 | 
            +
                                alias_of: nil
         | 
| 628 635 | 
             
                              )
         | 
| 629 636 | 
             
                            end
         | 
| 630 637 |  | 
| @@ -641,7 +648,8 @@ module RBS | |
| 641 648 | 
             
                          Definition::Method.new(
         | 
| 642 649 | 
             
                            super_method: nil,
         | 
| 643 650 | 
             
                            defs: defs + original.defs,
         | 
| 644 | 
            -
                            accessibility: original.accessibility
         | 
| 651 | 
            +
                            accessibility: original.accessibility,
         | 
| 652 | 
            +
                            alias_of: nil
         | 
| 645 653 | 
             
                          )
         | 
| 646 654 | 
             
                        end
         | 
| 647 655 | 
             
                      end
         | 
| @@ -650,66 +658,15 @@ module RBS | |
| 650 658 | 
             
                        each_member_with_accessibility(d.decl.members) do |member, accessibility|
         | 
| 651 659 | 
             
                          case member
         | 
| 652 660 | 
             
                          when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
         | 
| 653 | 
            -
                             | 
| 654 | 
            -
             | 
| 655 | 
            -
             | 
| 656 | 
            -
             | 
| 657 | 
            -
             | 
| 658 | 
            -
                                          nil
         | 
| 659 | 
            -
                                        else
         | 
| 660 | 
            -
                                          member.ivar_name || :"@#{member.name}"
         | 
| 661 | 
            -
                                        end
         | 
| 662 | 
            -
             | 
| 663 | 
            -
                            if member.is_a?(AST::Members::AttrReader) || member.is_a?(AST::Members::AttrAccessor)
         | 
| 664 | 
            -
                              definition.methods[name] = Definition::Method.new(
         | 
| 665 | 
            -
                                super_method: nil,
         | 
| 666 | 
            -
                                defs: [
         | 
| 667 | 
            -
                                  Definition::Method::TypeDef.new(
         | 
| 668 | 
            -
                                    type: MethodType.new(
         | 
| 669 | 
            -
                                      type_params: [],
         | 
| 670 | 
            -
                                      type: Types::Function.empty(type),
         | 
| 671 | 
            -
                                      block: nil,
         | 
| 672 | 
            -
                                      location: nil
         | 
| 673 | 
            -
                                    ),
         | 
| 674 | 
            -
                                    member: member,
         | 
| 675 | 
            -
                                    defined_in: type_name,
         | 
| 676 | 
            -
                                    implemented_in: type_name
         | 
| 677 | 
            -
                                  )
         | 
| 678 | 
            -
                                ],
         | 
| 661 | 
            +
                            if member.kind == :instance
         | 
| 662 | 
            +
                              build_attribute(
         | 
| 663 | 
            +
                                type_name: type_name,
         | 
| 664 | 
            +
                                definition: definition,
         | 
| 665 | 
            +
                                member: member,
         | 
| 679 666 | 
             
                                accessibility: accessibility
         | 
| 680 667 | 
             
                              )
         | 
| 681 668 | 
             
                            end
         | 
| 682 669 |  | 
| 683 | 
            -
                            if member.is_a?(AST::Members::AttrWriter) || member.is_a?(AST::Members::AttrAccessor)
         | 
| 684 | 
            -
                              definition.methods[:"#{name}="] = Definition::Method.new(
         | 
| 685 | 
            -
                                super_method: nil,
         | 
| 686 | 
            -
                                defs: [
         | 
| 687 | 
            -
                                  Definition::Method::TypeDef.new(
         | 
| 688 | 
            -
                                    type: MethodType.new(
         | 
| 689 | 
            -
                                      type_params: [],
         | 
| 690 | 
            -
                                      type: Types::Function.empty(type).update(
         | 
| 691 | 
            -
                                        required_positionals: [Types::Function::Param.new(name: name, type: type)]
         | 
| 692 | 
            -
                                      ),
         | 
| 693 | 
            -
                                      block: nil,
         | 
| 694 | 
            -
                                      location: nil
         | 
| 695 | 
            -
                                    ),
         | 
| 696 | 
            -
                                    member: member,
         | 
| 697 | 
            -
                                    defined_in: type_name,
         | 
| 698 | 
            -
                                    implemented_in: type_name
         | 
| 699 | 
            -
                                  ),
         | 
| 700 | 
            -
                                ],
         | 
| 701 | 
            -
                                accessibility: accessibility
         | 
| 702 | 
            -
                              )
         | 
| 703 | 
            -
                            end
         | 
| 704 | 
            -
             | 
| 705 | 
            -
                            if ivar_name
         | 
| 706 | 
            -
                              definition.instance_variables[ivar_name] = Definition::Variable.new(
         | 
| 707 | 
            -
                                parent_variable: nil,
         | 
| 708 | 
            -
                                type: type,
         | 
| 709 | 
            -
                                declared_in: type_name
         | 
| 710 | 
            -
                              )
         | 
| 711 | 
            -
                            end
         | 
| 712 | 
            -
             | 
| 713 670 | 
             
                          when AST::Members::InstanceVariable
         | 
| 714 671 | 
             
                            definition.instance_variables[member.name] = Definition::Variable.new(
         | 
| 715 672 | 
             
                              parent_variable: nil,
         | 
| @@ -747,7 +704,15 @@ module RBS | |
| 747 704 | 
             
                                location: member.location
         | 
| 748 705 | 
             
                              )
         | 
| 749 706 |  | 
| 750 | 
            -
                               | 
| 707 | 
            +
                              original_method = definition.methods[member.old_name]
         | 
| 708 | 
            +
             | 
| 709 | 
            +
                              definition.methods[member.new_name] = Definition::Method.new(
         | 
| 710 | 
            +
                                super_method: original_method.super_method,
         | 
| 711 | 
            +
                                defs: original_method.defs,
         | 
| 712 | 
            +
                                accessibility: original_method.accessibility,
         | 
| 713 | 
            +
                                alias_of: original_method,
         | 
| 714 | 
            +
                                annotations: original_method.annotations
         | 
| 715 | 
            +
                              )
         | 
| 751 716 | 
             
                            end
         | 
| 752 717 | 
             
                          end
         | 
| 753 718 | 
             
                        end
         | 
| @@ -838,7 +803,10 @@ module RBS | |
| 838 803 | 
             
                    entry = env.class_decls[type_name]
         | 
| 839 804 |  | 
| 840 805 | 
             
                    self_type = Types::ClassSingleton.new(name: type_name, location: nil)
         | 
| 841 | 
            -
                    ancestors =  | 
| 806 | 
            +
                    ancestors = Definition::SingletonAncestors.new(
         | 
| 807 | 
            +
                      type_name: type_name,
         | 
| 808 | 
            +
                      ancestors: [Definition::Ancestor::Singleton.new(name: type_name)]
         | 
| 809 | 
            +
                    )
         | 
| 842 810 |  | 
| 843 811 | 
             
                    Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
         | 
| 844 812 | 
             
                      method_definition_members(type_name, entry, kind: :singleton).each do |method_name, array|
         | 
| @@ -855,7 +823,8 @@ module RBS | |
| 855 823 | 
             
                          defs: method_def&.yield_self do |method_def|
         | 
| 856 824 | 
             
                            method_def.defs.map {|defn| defn.update(implemented_in: type_name) }
         | 
| 857 825 | 
             
                          end || [],
         | 
| 858 | 
            -
                          accessibility: visibility
         | 
| 826 | 
            +
                          accessibility: visibility,
         | 
| 827 | 
            +
                          alias_of: nil
         | 
| 859 828 | 
             
                        )
         | 
| 860 829 | 
             
                        definition.methods[method_name] = members.inject(m) do |original, new|
         | 
| 861 830 | 
             
                          defs = new.types.map do |type|
         | 
| @@ -869,7 +838,8 @@ module RBS | |
| 869 838 | 
             
                          Definition::Method.new(
         | 
| 870 839 | 
             
                            super_method: nil,
         | 
| 871 840 | 
             
                            defs: defs + original.defs,
         | 
| 872 | 
            -
                            accessibility: original.accessibility
         | 
| 841 | 
            +
                            accessibility: original.accessibility,
         | 
| 842 | 
            +
                            alias_of: nil
         | 
| 873 843 | 
             
                          )
         | 
| 874 844 | 
             
                        end
         | 
| 875 845 | 
             
                      end
         | 
| @@ -893,7 +863,14 @@ module RBS | |
| 893 863 | 
             
                                location: member.location
         | 
| 894 864 | 
             
                              )
         | 
| 895 865 |  | 
| 896 | 
            -
                               | 
| 866 | 
            +
                              original_method = definition.methods[member.old_name]
         | 
| 867 | 
            +
                              definition.methods[member.new_name] = Definition::Method.new(
         | 
| 868 | 
            +
                                super_method: original_method.super_method,
         | 
| 869 | 
            +
                                defs: original_method.defs,
         | 
| 870 | 
            +
                                accessibility: original_method.accessibility,
         | 
| 871 | 
            +
                                alias_of: original_method,
         | 
| 872 | 
            +
                                annotations: original_method.annotations
         | 
| 873 | 
            +
                              )
         | 
| 897 874 | 
             
                            end
         | 
| 898 875 | 
             
                          end
         | 
| 899 876 | 
             
                        end
         | 
| @@ -945,14 +922,23 @@ module RBS | |
| 945 922 | 
             
                              )
         | 
| 946 923 | 
             
                            end,
         | 
| 947 924 | 
             
                            accessibility: :public,
         | 
| 948 | 
            -
                            annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")]
         | 
| 925 | 
            +
                            annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")],
         | 
| 926 | 
            +
                            alias_of: nil
         | 
| 949 927 | 
             
                          )
         | 
| 950 928 | 
             
                        end
         | 
| 951 929 | 
             
                      end
         | 
| 952 930 |  | 
| 953 931 | 
             
                      entry.decls.each do |d|
         | 
| 954 | 
            -
                        each_member_with_accessibility(d.decl.members) do |member,  | 
| 932 | 
            +
                        each_member_with_accessibility(d.decl.members) do |member, accessibility|
         | 
| 955 933 | 
             
                          case member
         | 
| 934 | 
            +
                          when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
         | 
| 935 | 
            +
                            if member.kind == :singleton
         | 
| 936 | 
            +
                              build_attribute(type_name: type_name,
         | 
| 937 | 
            +
                                              definition: definition,
         | 
| 938 | 
            +
                                              member: member,
         | 
| 939 | 
            +
                                              accessibility: accessibility)
         | 
| 940 | 
            +
                            end
         | 
| 941 | 
            +
             | 
| 956 942 | 
             
                          when AST::Members::ClassInstanceVariable
         | 
| 957 943 | 
             
                            definition.instance_variables[member.name] = Definition::Variable.new(
         | 
| 958 944 | 
             
                              parent_variable: nil,
         | 
| @@ -973,6 +959,70 @@ module RBS | |
| 973 959 | 
             
                  end
         | 
| 974 960 | 
             
                end
         | 
| 975 961 |  | 
| 962 | 
            +
                def build_attribute(type_name:, definition:, member:, accessibility:)
         | 
| 963 | 
            +
                  name = member.name
         | 
| 964 | 
            +
                  type = member.type
         | 
| 965 | 
            +
             | 
| 966 | 
            +
                  ivar_name = case member.ivar_name
         | 
| 967 | 
            +
                              when false
         | 
| 968 | 
            +
                                nil
         | 
| 969 | 
            +
                              else
         | 
| 970 | 
            +
                                member.ivar_name || :"@#{member.name}"
         | 
| 971 | 
            +
                              end
         | 
| 972 | 
            +
             | 
| 973 | 
            +
                  if member.is_a?(AST::Members::AttrReader) || member.is_a?(AST::Members::AttrAccessor)
         | 
| 974 | 
            +
                    definition.methods[name] = Definition::Method.new(
         | 
| 975 | 
            +
                      super_method: nil,
         | 
| 976 | 
            +
                      defs: [
         | 
| 977 | 
            +
                        Definition::Method::TypeDef.new(
         | 
| 978 | 
            +
                          type: MethodType.new(
         | 
| 979 | 
            +
                            type_params: [],
         | 
| 980 | 
            +
                            type: Types::Function.empty(type),
         | 
| 981 | 
            +
                            block: nil,
         | 
| 982 | 
            +
                            location: nil
         | 
| 983 | 
            +
                          ),
         | 
| 984 | 
            +
                          member: member,
         | 
| 985 | 
            +
                          defined_in: type_name,
         | 
| 986 | 
            +
                          implemented_in: type_name
         | 
| 987 | 
            +
                        )
         | 
| 988 | 
            +
                      ],
         | 
| 989 | 
            +
                      accessibility: accessibility,
         | 
| 990 | 
            +
                      alias_of: nil
         | 
| 991 | 
            +
                    )
         | 
| 992 | 
            +
                  end
         | 
| 993 | 
            +
             | 
| 994 | 
            +
                  if member.is_a?(AST::Members::AttrWriter) || member.is_a?(AST::Members::AttrAccessor)
         | 
| 995 | 
            +
                    definition.methods[:"#{name}="] = Definition::Method.new(
         | 
| 996 | 
            +
                      super_method: nil,
         | 
| 997 | 
            +
                      defs: [
         | 
| 998 | 
            +
                        Definition::Method::TypeDef.new(
         | 
| 999 | 
            +
                          type: MethodType.new(
         | 
| 1000 | 
            +
                            type_params: [],
         | 
| 1001 | 
            +
                            type: Types::Function.empty(type).update(
         | 
| 1002 | 
            +
                              required_positionals: [Types::Function::Param.new(name: name, type: type)]
         | 
| 1003 | 
            +
                            ),
         | 
| 1004 | 
            +
                            block: nil,
         | 
| 1005 | 
            +
                            location: nil
         | 
| 1006 | 
            +
                          ),
         | 
| 1007 | 
            +
                          member: member,
         | 
| 1008 | 
            +
                          defined_in: type_name,
         | 
| 1009 | 
            +
                          implemented_in: type_name
         | 
| 1010 | 
            +
                        ),
         | 
| 1011 | 
            +
                      ],
         | 
| 1012 | 
            +
                      accessibility: accessibility,
         | 
| 1013 | 
            +
                      alias_of: nil
         | 
| 1014 | 
            +
                    )
         | 
| 1015 | 
            +
                  end
         | 
| 1016 | 
            +
             | 
| 1017 | 
            +
                  if ivar_name
         | 
| 1018 | 
            +
                    definition.instance_variables[ivar_name] = Definition::Variable.new(
         | 
| 1019 | 
            +
                      parent_variable: nil,
         | 
| 1020 | 
            +
                      type: type,
         | 
| 1021 | 
            +
                      declared_in: type_name
         | 
| 1022 | 
            +
                    )
         | 
| 1023 | 
            +
                  end
         | 
| 1024 | 
            +
                end
         | 
| 1025 | 
            +
             | 
| 976 1026 | 
             
                def merge_definitions(type_name, pairs, entry:, self_type:, ancestors:)
         | 
| 977 1027 | 
             
                  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
         | 
| 978 1028 | 
             
                    pairs.reverse_each do |ancestor, current_definition|
         | 
| @@ -1029,7 +1079,8 @@ module RBS | |
| 1029 1079 | 
             
                  methods[name] = Definition::Method.new(
         | 
| 1030 1080 | 
             
                    super_method: super_method,
         | 
| 1031 1081 | 
             
                    accessibility: method.accessibility,
         | 
| 1032 | 
            -
                    defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) }
         | 
| 1082 | 
            +
                    defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) },
         | 
| 1083 | 
            +
                    alias_of: nil
         | 
| 1033 1084 | 
             
                  )
         | 
| 1034 1085 | 
             
                end
         | 
| 1035 1086 |  | 
| @@ -1123,7 +1174,8 @@ module RBS | |
| 1123 1174 | 
             
                              implemented_in: nil
         | 
| 1124 1175 | 
             
                            )
         | 
| 1125 1176 | 
             
                          end,
         | 
| 1126 | 
            -
                          accessibility: :public
         | 
| 1177 | 
            +
                          accessibility: :public,
         | 
| 1178 | 
            +
                          alias_of: nil
         | 
| 1127 1179 | 
             
                        )
         | 
| 1128 1180 | 
             
                        definition.methods[member.name] = method
         | 
| 1129 1181 | 
             
                      end
         |