diff --git a/lib/ast.rb b/lib/ast.rb index 97ca4bd7ed192446053e249d62ae85737fee7a9c..4531ebf5c0f95f622e37fa5e8b88c5d834120a51 100644 --- a/lib/ast.rb +++ b/lib/ast.rb @@ -179,21 +179,17 @@ module Dhallish end def compute_type(ctx) - new_ctx = nil + new_ctx = Context.new ctx @vars.each { |decl| name, annot_type_expr, val = decl - annot_type = nil - act_type = val.compute_type(ctx) + act_type = val.compute_type(new_ctx) + if !annot_type_expr.nil? - type_type = annot_type_expr.compute_type(ctx) + type_type = annot_type_expr.compute_type(new_ctx) assert ("not a type after type annotation") { type_type.is_a? Types::Type } annot_type = type_type.metadata - assert ("Actual type of #{name}'s value (#{act_type}) doesn't match annotated type (#{annot_type})") {annot_type == act_type } - end - - if new_ctx.nil? - new_ctx = Context.new ctx + assert ("Actual type of #{name}'s value (#{act_type}) doesn't match annotated type (#{annot_type})") { annot_type == act_type } end new_ctx[name] = act_type