module TypedRb::Runtime::Normalization::Validations
Public Instance Methods
validate_function_signature(klass, method, signature, method_type)
click to toggle source
# File lib/typed/runtime/normalization/validations.rb, line 38 def validate_function_signature(klass, method, signature, method_type) if signature.is_a?(Hash) join = method_type == :instance ? '#' : '::' fail ::TypedRb::Types::TypeParsingError, "Declared method #{klass}#{join}#{method}(#{signature}) is not a valid arrow" end end
validate_method(class_methods_info, klass, method, method_type)
click to toggle source
# File lib/typed/runtime/normalization/validations.rb, line 24 def validate_method(class_methods_info, klass, method, method_type) if method_type == :instance unless (class_methods_info[:instance_methods]).include?(method.to_sym) fail ::TypedRb::Types::TypeParsingError, "Declared typed instance method '#{method}' not found for class '#{klass}'" end elsif method_type == :class unless class_methods_info[:all_methods].include?(method.to_sym) fail ::TypedRb::Types::TypeParsingError, "Declared typed class method '#{method}' not found for class '#{klass}'" end end end
validate_signature(type, normalized_signature)
click to toggle source
# File lib/typed/runtime/normalization/validations.rb, line 5 def validate_signature(type, normalized_signature) return if type == :class_variable || type == :instance_variable return if normalized_signature.is_a?(TypedRb::Types::TyFunction) fail ::TypedRb::Types::TypeParsingError, "Error parsing receiver, method signature: #{type} :: '#{normalized_signature}'" end
validate_signatures(normalized_signatures, klass, method)
click to toggle source
# File lib/typed/runtime/normalization/validations.rb, line 12 def validate_signatures(normalized_signatures, klass, method) arities = normalized_signatures.map(&:arity) duplicated_arities = arities.select { |arity| arities.count(arity) > 1 } duplicated_arities.each do |arity| duplicated = normalized_signatures.select { |signature| signature.arity == arity } unless duplicated.count == 2 && duplicated.first.block_type.nil? != duplicated.last.block_type.nil? error_message = "Duplicated arity '#{arity}' for method '#{klass}' / '#{method}'" fail ::TypedRb::Types::TypeParsingError, error_message end end end