From 3334db65040c4abd1a65b263a9052c9cb9b1f500 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Wed, 7 Jul 2010 08:35:45 -0700 Subject: [PATCH] Better error messages during compilation and fix for wide return types --- lib/duby/ast/flow.rb | 2 +- lib/duby/jvm/base.rb | 7 ++++++- lib/duby/jvm/types/methods.rb | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/duby/ast/flow.rb b/lib/duby/ast/flow.rb index 47aaee1..38913de 100644 --- a/lib/duby/ast/flow.rb +++ b/lib/duby/ast/flow.rb @@ -81,7 +81,7 @@ def infer(typer) @inferred_type = then_type.narrow(else_type) resolved! if condition_type else - raise Typer::InferenceError.new("if statement with incompatible result types") + raise Typer::InferenceError.new("if statement with incompatible result types #{then_type} and #{else_type}") end end else diff --git a/lib/duby/jvm/base.rb b/lib/duby/jvm/base.rb index f21e981..148d19b 100644 --- a/lib/duby/jvm/base.rb +++ b/lib/duby/jvm/base.rb @@ -15,7 +15,12 @@ def initialize(filename) end def compile(ast, expression = false) - ast.compile(self, expression) + begin + ast.compile(self, expression) + rescue => ex + Duby.print_error(ex.message, ast.position) + raise ex + end log "Compilation successful!" end diff --git a/lib/duby/jvm/types/methods.rb b/lib/duby/jvm/types/methods.rb index 9c1bc7a..9e1bac1 100644 --- a/lib/duby/jvm/types/methods.rb +++ b/lib/duby/jvm/types/methods.rb @@ -19,7 +19,7 @@ def convert_args(compiler, values, types=nil) # TODO varargs types ||= argument_types values.zip(types).each do |value, type| - value.compile(compiler, true) + compiler.compile(value, true) if type.primitive? && type != value.inferred_type value.inferred_type.widen(compiler.method, type) end @@ -208,7 +208,11 @@ def call(compiler, ast, expression) end unless expression || void? - compiler.method.pop + if return_type.wide? + compiler.method.pop2 + else + compiler.method.pop + end end end