Sha256: b96ff8b73407c35b0d53149d27418e46c1b34acf2d967de744e549c6f11b5542
Contents?: true
Size: 1.44 KB
Versions: 4
Compression:
Stored size: 1.44 KB
Contents
module RBS class Validator attr_reader :env attr_reader :resolver def initialize(env:, resolver:) @env = env @resolver = resolver end def absolute_type(type, context:) type.map_type_name do |type_name, _, type| resolver.resolve(type_name, context: context) || yield(type) end end # Validates presence of the relative type, and application arity match. def validate_type(type, context:) case type when Types::ClassInstance, Types::Interface if type.name.namespace.relative? type = absolute_type(type, context: context) do |type| NoTypeFoundError.check!(type.name.absolute!, env: env, location: type.location) end end type_params = case type when Types::ClassInstance env.class_decls[type.name]&.type_params when Types::Interface env.interface_decls[type.name]&.decl&.type_params end unless type_params raise NoTypeFoundError.new(type_name: type.name, location: type.location) end InvalidTypeApplicationError.check!( type_name: type.name, args: type.args, params: type_params.each.map(&:name), location: type.location ) end type.each_type do |type| validate_type(type, context: context) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rbs-0.8.0 | lib/rbs/validator.rb |
rbs-0.7.0 | lib/rbs/validator.rb |
rbs-0.6.0 | lib/rbs/validator.rb |
rbs-0.5.0 | lib/rbs/validator.rb |