Sha256: f8d0b916f7ec32019e4a5a316f31bd6dc8d46246a185602b52d26e62232c91eb

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

module Steep
  module AST
    module Types
      class Literal
        attr_reader :location
        attr_reader :value

        def initialize(value:, location: nil)
          @location = location
          @value = value
        end

        def ==(other)
          other.is_a?(Literal) &&
            other.value == value
        end

        def hash
          self.class.hash
        end

        alias eql? ==

        def subst(s)
          self
        end

        def to_s
          value.inspect
        end

        def free_variables
          Set.new
        end

        def level
          [0]
        end

        def with_location(new_location)
          self.class.new(location: new_location)
        end

        def back_type
          klass = case value
                  when Integer
                    Builtin::Integer
                  when String
                    Builtin::String
                  when Symbol
                    Builtin::Symbol
                  when true
                    Builtin::TrueClass
                  when false
                    Builtin::FalseClass
                  else
                    raise "Unexpected literal type: #{value.inspect}"
                  end

          Name::Instance.new(name: klass.module_name, args: [], location: location)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
steep-0.25.0 lib/steep/ast/types/literal.rb
steep-0.24.0 lib/steep/ast/types/literal.rb
steep-0.23.0 lib/steep/ast/types/literal.rb
steep-0.22.0 lib/steep/ast/types/literal.rb