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

Conversation

Projects
None yet
4 participants
@willhbr
Contributor

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

@willhbr willhbr force-pushed the willhbr:accepts_block branch from 1b68a4c to 49c5931 Aug 25, 2018

@RX14

RX14 approved these changes Aug 26, 2018

@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

4 checks passed

ci/circleci: test_darwin Your tests passed on CircleCI!
Details
ci/circleci: test_linux Your tests passed on CircleCI!
Details
ci/circleci: test_linux32 Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@bcardiff

This comment has been minimized.

Member

bcardiff commented Aug 26, 2018

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 willhbr:accepts_block branch Aug 26, 2018

@RX14 RX14 added the topic:compiler label Aug 28, 2018

omarroth added a commit to omarroth/crystal that referenced this pull request Nov 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment