Module: TypedRb::Runtime::Normalization::Validations
- Included in:
- BasicObject::TypeRegistry
- Defined in:
- lib/typed/runtime/normalization/validations.rb
Instance Method Summary collapse
- #validate_function_signature(klass, method, signature, method_type) ⇒ Object
- #validate_method(class_methods_info, klass, method, method_type) ⇒ Object
- #validate_signature(type, normalized_signature) ⇒ Object
- #validate_signatures(normalized_signatures, klass, method) ⇒ Object
Instance Method Details
#validate_function_signature(klass, method, signature, method_type) ⇒ Object
38 39 40 41 42 43 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# 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) ⇒ Object
5 6 7 8 9 10 |
# 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) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# 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? = "Duplicated arity '#{arity}' for method '#{klass}' / '#{method}'" fail ::TypedRb::Types::TypeParsingError, end end end |