Sha256: f81b804f8478dcf70d8a3bdce0569d62e522133ec008ff894f4d6457594d450d

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

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

      # ConstantEnv receives an Names::Module 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(name)
        cache[name] ||= begin
          constant = table.resolve_constant_reference(
            factory.type_name_1(name),
            context: context.map {|namespace| factory.namespace_1(namespace) }
          )

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
steep-0.24.0 lib/steep/type_inference/constant_env.rb
steep-0.23.0 lib/steep/type_inference/constant_env.rb
steep-0.22.0 lib/steep/type_inference/constant_env.rb
steep-0.21.0 lib/steep/type_inference/constant_env.rb
steep-0.20.0 lib/steep/type_inference/constant_env.rb
steep-0.19.0 lib/steep/type_inference/constant_env.rb
steep-0.18.0 lib/steep/type_inference/constant_env.rb
steep-0.17.1 lib/steep/type_inference/constant_env.rb
steep-0.17.0 lib/steep/type_inference/constant_env.rb
steep-0.16.3 lib/steep/type_inference/constant_env.rb
steep-0.16.2 lib/steep/type_inference/constant_env.rb
steep-0.16.1 lib/steep/type_inference/constant_env.rb