Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Jun 12, 2013
1 parent 2a0eb74 commit e18cb6d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/crystal/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,8 @@ def parse_args
var.out = true
var.location = @token.location
args << var

@instance_vars.add @token.value if @instance_vars
else
raise "expecting variable or instance variable after out"
end
Expand Down Expand Up @@ -952,6 +954,8 @@ def parse_args_space_consumed(allow_plus_and_minus = false)
var.out = true
var.location = @token.location
args << var

@instance_vars.add @token.value if @instance_vars
else
raise "expecting variable or instance variable after out"
end
Expand Down
1 change: 1 addition & 0 deletions lib/crystal/to_s.rb
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def visit_self_type(node)
end

def visit_instance_var(node)
@str << "out " if node.out
@str << node.name
end

Expand Down
11 changes: 7 additions & 4 deletions lib/crystal/type_inference/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,15 @@ def recalculate_lib_call

def check_out_args(untyped_def)
untyped_def.args.each_with_index do |arg, i|
if arg.out && self.args[i]
unless self.args[i].out
self.args[i].raise "argument \##{i + 1} to #{untyped_def.owner}.#{untyped_def.name} must be passed as 'out'"
call_arg = self.args[i]
if arg.out && call_arg
unless call_arg.out
call_arg.raise "argument \##{i + 1} to #{untyped_def.owner}.#{untyped_def.name} must be passed as 'out'"
end
var = parent_visitor.lookup_var_or_instance_var(self.args[i])
var = parent_visitor.lookup_var_or_instance_var(call_arg)
var.bind_to arg
elsif !arg.out && (call_arg.is_a?(Var) || call_arg.is_a?(InstanceVar)) && call_arg.out
call_arg.raise "argument \##{i + 1} to #{untyped_def.owner}.#{untyped_def.name} cannot be passed as 'out'"
end
end
end
Expand Down

0 comments on commit e18cb6d

Please sign in to comment.