Skip to content

Commit

Permalink
Better error messages during compilation and fix for wide return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Brown committed Jul 7, 2010
1 parent 6aa45b9 commit 3334db6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/duby/ast/flow.rb
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/duby/jvm/base.rb
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions lib/duby/jvm/types/methods.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 3334db6

Please sign in to comment.