Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: incorrect debug info for closured self #6346

Merged
merged 1 commit into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions spec/compiler/codegen/debug_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,22 @@ describe "Code gen: debug" do
end
), debug: Crystal::Debug::All)
end

it "doesn't emit incorrect debug info for closured self" do
codegen(%(
def foo(&block : Int32 ->)
block.call(1)
end

class Foo
def bar
foo do
self
end
end
end

Foo.new.bar
), debug: Crystal::Debug::All)
end
end
4 changes: 3 additions & 1 deletion src/compiler/crystal/codegen/fun.cr
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class Crystal::CodeGenVisitor
args_offset = !is_fun_literal && self_type.passed_as_self? ? 2 : 1
location = target_def.location
context.vars.each do |name, var|
if name == "self"
# Self always comes as the first parameter, unless it's a closure:
# then it will be fetched from the closure data.
if name == "self" && !is_closure
declare_parameter(name, var.type, 1, var.pointer, location)
elsif arg_no = args.index { |arg| arg.name == name }
declare_parameter(name, var.type, arg_no + args_offset, var.pointer, location)
Expand Down