Skip to content

Commit

Permalink
Add accepts_block? macromethod to Def
Browse files Browse the repository at this point in the history
  • Loading branch information
willhbr committed Aug 25, 2018
1 parent a56dcbe commit 1b68a4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/compiler/macro/macro_methods_spec.cr
Expand Up @@ -1304,6 +1304,11 @@ module Crystal
assert_macro "x", %({{x.block_arg}}), [Def.new("some_def")] of ASTNode, ""
end

it "executes accepts_block?" do
assert_macro "x", %({{x.accepts_block?}}), [Def.new("some_def", ["x".arg, "y".arg], yields: 1)] of ASTNode, "true"
assert_macro "x", %({{x.accepts_block?}}), [Def.new("some_def")] of ASTNode, "false"
end

it "executes return_type" do
assert_macro "x", %({{x.return_type}}), [Def.new("some_def", ["x".arg, "y".arg], return_type: "b".arg)] of ASTNode, "b"
assert_macro "x", %({{x.return_type}}), [Def.new("some_def")] of ASTNode, ""
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/crystal/macros/methods.cr
Expand Up @@ -1242,6 +1242,8 @@ module Crystal
interpret_argless_method(method, args) { @double_splat || Nop.new }
when "block_arg"
interpret_argless_method(method, args) { @block_arg || Nop.new }
when "accepts_block?"
interpret_argless_method(method, args) { BoolLiteral.new(@yields != nil) }
when "return_type"
interpret_argless_method(method, args) { @return_type || Nop.new }
when "body"
Expand Down

0 comments on commit 1b68a4c

Please sign in to comment.