Sha256: 28e9794963ddfb27cb78f9d16c60056ad213bd6ebe5c4a5391a477afa9571a64

Contents?: true

Size: 1.13 KB

Versions: 23

Compression:

Stored size: 1.13 KB

Contents

module Steep
  module Subtyping
    class VariableOccurence
      attr_reader :params
      attr_reader :returns

      def initialize
        @params = Set.new
        @returns = Set.new
      end

      def add_method_type(method_type)
        method_type.type.params.each_type do |type|
          each_var(type) do |var|
            params << var
          end
        end
        each_var(method_type.type.return_type) do |var|
          returns << var
        end

        method_type.block&.yield_self do |block|
          block.type.params.each_type do |type|
            each_var(type) do |var|
              params << var
            end
          end
          each_var(block.type.return_type) do |var|
            returns << var
          end
        end

        params.subtract(returns)
      end

      def each_var(type, &block)
        type.free_variables.each(&block)
      end

      def strictly_return?(var)
        !params.member?(var) && returns.member?(var)
      end

      def self.from_method_type(method_type)
        self.new.tap do |occurence|
          occurence.add_method_type(method_type)
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
steep-1.0.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.52.2 lib/steep/subtyping/variable_occurrence.rb
steep-0.52.1 lib/steep/subtyping/variable_occurrence.rb
steep-0.52.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.51.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.50.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.49.1 lib/steep/subtyping/variable_occurrence.rb
steep-0.49.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.48.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.47.1 lib/steep/subtyping/variable_occurrence.rb
steep-0.47.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.46.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.45.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.44.1 lib/steep/subtyping/variable_occurrence.rb
steep-0.44.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.43.1 lib/steep/subtyping/variable_occurrence.rb
steep-0.43.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.42.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.41.0 lib/steep/subtyping/variable_occurrence.rb
steep-0.40.0 lib/steep/subtyping/variable_occurrence.rb