Sha256: da3a291d6f67abdfa82d0129a332ef8c78ab2272691715f7d44820b5cc649f8f

Contents?: true

Size: 1006 Bytes

Versions: 17

Compression:

Stored size: 1006 Bytes

Contents

module Steep
  module TypeInference
    class ConstantEnv
      attr_reader :context
      attr_reader :cache
      attr_reader :factory
      attr_reader :table

      # ConstantEnv receives an TypeName as a context, not a Namespace, because this is a simulation of Ruby.
      # Any namespace is a module or class.
      def initialize(factory:, context:)
        @cache = {}
        @factory = factory
        @context = context
        @table = RBS::ConstantTable.new(builder: factory.definition_builder)
      end

      def lookup_constant(name)
        table.resolve_constant_reference(name, context: context)
      end

      def lookup(name)
        cache[name] ||= begin
          constant = lookup_constant(name)

          if constant
            factory.type(constant.type)
          end
        rescue => exn
          Steep.logger.debug "Looking up a constant failed: name=#{name}, context=[#{context.join(", ")}], error=#{exn.inspect}"
          nil
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
steep-0.50.0 lib/steep/type_inference/constant_env.rb
steep-0.49.1 lib/steep/type_inference/constant_env.rb
steep-0.49.0 lib/steep/type_inference/constant_env.rb
steep-0.48.0 lib/steep/type_inference/constant_env.rb
steep-0.47.1 lib/steep/type_inference/constant_env.rb
steep-0.47.0 lib/steep/type_inference/constant_env.rb
steep-0.46.0 lib/steep/type_inference/constant_env.rb
steep-0.45.0 lib/steep/type_inference/constant_env.rb
steep-0.44.1 lib/steep/type_inference/constant_env.rb
steep-0.44.0 lib/steep/type_inference/constant_env.rb
steep-0.43.1 lib/steep/type_inference/constant_env.rb
steep-0.43.0 lib/steep/type_inference/constant_env.rb
steep-0.42.0 lib/steep/type_inference/constant_env.rb
steep-0.41.0 lib/steep/type_inference/constant_env.rb
steep-0.40.0 lib/steep/type_inference/constant_env.rb
steep-0.39.0 lib/steep/type_inference/constant_env.rb
steep-0.38.0 lib/steep/type_inference/constant_env.rb