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

Add accepts_block? macromethod to Def #6604

Merged
merged 1 commit into from
Aug 26, 2018
Merged

Add accepts_block? macromethod to Def #6604

merged 1 commit into from
Aug 26, 2018

Conversation

willhbr
Copy link
Contributor

@willhbr willhbr commented Aug 25, 2018

Works around #5334 by adding .accepts_block? macro method which is true if the method can be called with a block. This is useful for macros that want to dispatch correctly to a method.

The example code from that bug (edited to use the new method):

class Foo
  macro finished
    {% for method in @type.methods %}
      {% puts method.accepts_block? %}
    {% end %}
  end

  def no_block
  end

  def just_yield
    yield 4
  end

  def yield_and_block(&block)
    yield 4
  end

  def yield_and_block_with_type(&block : Int32 ->)
    yield 4
  end
end

Gives the output as expected:

false
true
true
true

@bcardiff bcardiff added this to the 0.26.1 milestone Aug 26, 2018
@bcardiff bcardiff merged commit 7d38d2b into crystal-lang:master Aug 26, 2018
@bcardiff
Copy link
Member

Adding this to 0.26.1 since it would make it possible to use it in the stdlib for 0.27.0

@willhbr willhbr deleted the accepts_block branch August 26, 2018 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants