Method: Uinit::Type::Composition#check!

Defined in:
lib/uinit/type/composition.rb

#check!(value, depth) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/uinit/type/composition.rb', line 48

def check!(value, depth)
  errors = []
  is = true

  begin
    operand.check!(value, depth + 1)
  rescue Error => e
    errors << e
    is = false
  end

  compositions.each do |operator, operand|
    break if is && operator == UNION
    next if !is && operator == INTERSECTION

    begin
      operand.check!(value, depth + 1)
      is = true
    rescue Error => e
      errors << e
      is = false
    end
  end

  return value if is

  type_error!(value, errors.max_by(&:depth))
end