Module: Jade::Frontend::TypeChecking::Inference::Body
- Included in:
- Body
- Defined in:
- lib/jade/frontend/type_checking/inference/body.rb
Instance Method Summary collapse
Methods included from Helpers
check, generalize, instantiate, type_from_symbol, unify
Instance Method Details
#infer(node, registry, state, expected) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jade/frontend/type_checking/inference/body.rb', line 9 def infer(node, registry, state, expected) node => AST::Body(expressions:) *first_expressions, last_expression = expressions first_state, first_cs = first_expressions .reduce([state, []]) do |(acc, cs), expr| new_state, result = check( expr, registry, acc, Expected.infer(state.fresh), ) [new_state, cs + result.constraints] end last_state, last_result = check( last_expression, registry, first_state, expected, ) first_cs .map { last_state.env.substitution.apply(it) } .then do last_result .with(constraints: it + last_result.constraints) .then { |result| [last_state, result] } end end |