Sha256: a99f092a294a230dcee8283be4738d925d3c9582147a62b5590fdcd831b75056

Contents?: true

Size: 933 Bytes

Versions: 10

Compression:

Stored size: 933 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(name)
        cache[name] ||= begin
          constant = table.resolve_constant_reference(name, context: context)

          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

10 entries across 10 versions & 1 rubygems

Version Path
steep-0.37.0 lib/steep/type_inference/constant_env.rb
steep-0.36.0 lib/steep/type_inference/constant_env.rb
steep-0.35.0 lib/steep/type_inference/constant_env.rb
steep-0.34.0 lib/steep/type_inference/constant_env.rb
steep-0.33.0 lib/steep/type_inference/constant_env.rb
steep-0.32.0 lib/steep/type_inference/constant_env.rb
steep-0.31.1 lib/steep/type_inference/constant_env.rb
steep-0.31.0 lib/steep/type_inference/constant_env.rb
steep-0.30.0 lib/steep/type_inference/constant_env.rb
steep-0.29.0 lib/steep/type_inference/constant_env.rb