Fix "no anonymous block parameter" in ruby 3.1#51476
Conversation
|
I wasn't able to reproduce with the one file repro. I tried to fix the repro, but I am getting inconsistent results (first run give a different error). I was able to reproduce on both Ubuntu and Nixos. Here's a repo for the repro on ubuntu: https://github.com/JoeDupuis/rails_repro_51476 Issue happens on 3.1, but doesn't affect 3.2 Started on this commit: 5d528ba |
|
I saw this on 3.1.0, but upgrading to a newer 3.1 patch resolved the issue for me. (3.1.3 worked for me.) |
skipkayhil
left a comment
There was a problem hiding this comment.
I think this is a good change seems its seem like anonymous block param support is spotty across Ruby versions (ex. rubocop/rubocop#12571).
I searched the Rails repo for any more occurrences and found just one more:
$ rg '&\)'
actionpack/test/dispatch/request_test.rb
1234: %w(; &).each do |sep|
activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
177: def cache(&)
178: pool.enable_query_cache(&)
189: def uncached(dirties: true, &)
190: pool.disable_query_cache(dirties: dirties, &)
activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
678: # ALTER TABLE "products" ADD CONSTRAINT price_check EXCLUDE USING gist (price WITH =, availability_range WITH &&)
activesupport/lib/active_support/evented_file_update_checker.rb
178: paths.map { |path| path.ascend.to_a }.reduce(&:&)&.first
Can you also change the cache(&) on 177?
|
Should we just rubocop against anonymous blocks until we drop Ruby 3.1 support? The newer syntax is a small nicety, but it doesn't seem worth tangling with edge cases if we can just wait a while instead. |
Also change another anonymous block to a named block as requested by skipkayhil, although it does not trigger the same error as the method does not contain any keyword arguments.
3170805 to
f2addb5
Compare
|
It is likely duplicate with https://bugs.ruby-lang.org/issues/18673 |
|
The alternative is to bump the ruby version requirement to 3.1.3. But it's perhaps a bit weird. |
Motivation / Background
On
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu] (e.g. Ubuntu 23.10), simple rails commands fail with
no anonymous block parameter:One file repro:
This Pull Request has been created to fix this issue.
Detail
I do not know why this triggers "no anonymous block parameter", as the parameter is clearly there.
It was introduced when a named parameter was added, without the named parameter the error does not occur.
However, converting to a named block parameter fixes this issue.