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