diff --git a/lib/ast.rb b/lib/ast.rb index 97ca4bd7ed192446053e249d62ae85737fee7a9c..539aa6ec4c0c7fa9b91072c4ee9ba44897f6f28c 100644 --- a/lib/ast.rb +++ b/lib/ast.rb @@ -276,14 +276,15 @@ module Dhallish arg_type = @arg.compute_type ctx fn_type = @fn.compute_type ctx - if arg_type.is_a? Types::Type + assert("only functions can be called, not #{fn_type}") { fn_type.is_a? Types::Function } + + if arg_type.is_a? Types::Type and !fn_type.unres.nil? assert ("argument type mismatch: expected: #{fn_type.argtype}, got: #{arg_type}") { fn_type.argtype.is_a? Types::Type } - fn_type = Types::resolve(fn_type, fn_type.unres, arg_type.metadata) + Types::resolve(fn_type.restype, fn_type.unres, arg_type.metadata) else assert ("argument type mismatch: expected: #{fn_type.argtype}, got: #{arg_type}") { fn_type.argtype == arg_type } + fn_type.restype end - - fn_type.restype end def evaluate(ctx) diff --git a/lib/types.rb b/lib/types.rb index afa6f7fde7b2df86fd3c92ae12c277c31811dec5..587b1ff3929d599bcb808485f2bf0396485ac6cf 100644 --- a/lib/types.rb +++ b/lib/types.rb @@ -134,7 +134,11 @@ module Dhallish if orgtype.restype.nil? Function.new(resolve(orgtype.argtype, name, newtype), nil, orgtype.unres) else - Function.new(resolve(orgtype.argtype, name, newtype), resolve(orgtype.restype, name, newtype), orgtype.unres) + restype = orgtype.restype + if orgtype.unres.nil? or orgtype.unres != name + restype = resolve(orgtype.restype, name, newtype) + end + Function.new(resolve(orgtype.argtype, name, newtype), restype, orgtype.unres) end when Optional Optional.new(resolve(orgtype.type, name, newtype))