crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Compiler doesn't understand block when using brackets

Open xendk opened this issue 1 year ago • 1 comments

(Apologies if this has already been filed, but it's difficult to search for)

The parser does not like block arguments on the var[] syntax. Example:

class Test
  def [](key, &block)
    yield
  end
end

t = Test.new
t["test"] { puts "test" }

Same with do...end. The t.[]("test") { puts "test" } it's sugar for, works fine, but that's pretty ugly in my opinion.

xendk avatar Nov 12 '23 19:11 xendk

For the record, this works in Ruby

HertzDevil avatar Dec 27 '23 19:12 HertzDevil