Sha256: f684c066dc4bea5cacf17b294b4d02c19b201425b0a45d3b7024b180a987f748

Contents?: true

Size: 1.27 KB

Versions: 44

Compression:

Stored size: 1.27 KB

Contents

module Steep
  module AST
    module Types
      class Masked
        attr_reader :location
        attr_reader :type
        attr_reader :mask

        def initialize(type:, mask:, location:)
          @type = type
          @mask = mask
          @location = location
        end

        def ==(other)
          other.is_a?(Masked) &&
            other.type == type &&
            other.mask == mask
        end

        alias eql? ==

        def hash
          self.class.hash ^ type.hash ^ mask.hash
        end

        def to_json(*a)
          { class: :masked,
            type: type,
            mask: mask,
            location: location }.to_json(*a)
        end

        def to_s(level = 0)
          "masked(#{type}|#{mask})"
        end

        def free_variables
          @fvs ||= Set.new.tap do |set|
            set.merge(type.free_variables)
            set.merge(mask.free_variables)
          end
        end

        def each_type(&block)
          if block_given?
            yield type
            yield mask
          else
            enum_for :each_type
          end
        end

        def sub(s)
          self.class.new(type: type.sub(s),
                         mask: mask.sub(s),
                         location: location)
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
steep-1.3.0.pre.2 lib/steep/ast/types.rb
steep-1.3.0.pre.1 lib/steep/ast/types.rb
steep-1.2.1 lib/steep/ast/types.rb
steep-1.2.0 lib/steep/ast/types.rb
steep-1.2.0.pre.1 lib/steep/ast/types.rb
steep-1.1.1 lib/steep/ast/types.rb
steep-1.1.0 lib/steep/ast/types.rb
steep-1.1.0.pre.1 lib/steep/ast/types.rb
steep-1.0.2 lib/steep/ast/types.rb
steep-1.0.1 lib/steep/ast/types.rb
steep-1.0.0 lib/steep/ast/types.rb
steep-0.52.2 lib/steep/ast/types.rb
steep-0.52.1 lib/steep/ast/types.rb
steep-0.52.0 lib/steep/ast/types.rb
steep-0.51.0 lib/steep/ast/types.rb
steep-0.50.0 lib/steep/ast/types.rb
steep-0.49.1 lib/steep/ast/types.rb
steep-0.49.0 lib/steep/ast/types.rb
steep-0.48.0 lib/steep/ast/types.rb
steep-0.47.1 lib/steep/ast/types.rb