Skip to content
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
8 changes: 4 additions & 4 deletions spec/compiler/normalize/def_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ module Crystal
end

it "expands with named argument and yield" do
a_def = parse("def foo(x = 1, y = 2); yield x + y; end").as(Def)
a_def = parse("def foo(x = 1, y = 2, &); yield x + y; end").as(Def)
actual = a_def.expand_default_arguments(Program.new, 0, ["y"])
actual.to_s.should eq("def foo:y(y)\n x = 1\n yield x + y\nend")
actual.to_s.should eq("def foo:y(y, &)\n x = 1\n yield x + y\nend")
end

# Small optimizations: no need to create a separate def in these cases
Expand Down Expand Up @@ -147,9 +147,9 @@ module Crystal
end

it "expands with magic constant with named arg with yield" do
a_def = parse("def foo(x, file = __FILE__, line = __LINE__); yield x, file, line; end").as(Def)
a_def = parse("def foo(x, file = __FILE__, line = __LINE__, &); yield x, file, line; end").as(Def)
other_def = a_def.expand_default_arguments(Program.new, 1, ["line"])
other_def.to_s.should eq("def foo:line(x, line, file = __FILE__)\n yield x, file, line\nend")
other_def.to_s.should eq("def foo:line(x, line, file = __FILE__, &)\n yield x, file, line\nend")
end

it "expands a def with double splat and no args" do
Expand Down
4 changes: 4 additions & 0 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,8 @@ describe "ASTNode#to_s" do
expect_to_s "->::foo(Int32, String)"
expect_to_s "->::Foo::Bar.foo"
expect_to_s "yield(1)"
expect_to_s "def foo\n yield\nend", "def foo(&)\n yield\nend"
expect_to_s "def foo(x)\n yield\nend", "def foo(x, &)\n yield\nend"
expect_to_s "def foo(**x)\n yield\nend", "def foo(**x, &)\n yield\nend"
expect_to_s "macro foo(x)\n yield\nend"
end
2 changes: 1 addition & 1 deletion spec/compiler/semantic/restrictions_augmenter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe "Semantic: restrictions augmenter" do

it "doesn't augment if assigned inside block" do
expect_no_augment <<-CRYSTAL
def foo
def foo(&)
yield
end
class Foo
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ module Crystal
@str << '.'
end
@str << node.name
if node.args.size > 0 || node.block_arg || node.double_splat
if node.args.size > 0 || node.block_arity || node.double_splat
@str << '('
printed_arg = false
node.args.each_with_index do |arg, i|
Expand All @@ -633,7 +633,9 @@ module Crystal
@current_arg_type = :block_arg
@str << ", " if printed_arg
block_arg.accept self
printed_arg = true
elsif node.block_arity
@str << ", " if printed_arg
@str << '&'
end
@str << ')'
end
Expand Down