-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Set#initialize has two forms:
- No arguments, which just creates an empty
Set. - One
Enumerableargument, used to populate the newSet.
If a block is passed in, it is only used along the one-argument path. The zero-argument path ignores it and does not warn.
This led to a behavior difference in JRuby's Set, which does warn if no arguments are passed and a block is given: jruby/jruby#8728 (comment)
[] jruby94 $ ruby -v -rset -e 'p Set.new {}'
jruby 9.4.13.0-SNAPSHOT (3.1.4) 2025-03-31 e0de6e19d3 OpenJDK 64-Bit Server VM 21.0.6+7-LTS on 21.0.6+7-LTS +jit [arm64-darwin]
-e:1: warning: given block not used
#<Set: {}>
[] jruby94 $ ruby -v -rset -e 'p Set.new([]) {}'
jruby 9.4.13.0-SNAPSHOT (3.1.4) 2025-03-31 e0de6e19d3 OpenJDK 64-Bit Server VM 21.0.6+7-LTS on 21.0.6+7-LTS +jit [arm64-darwin]
#<Set: {}>
With CRuby moving toward emitting warnings when passed blocks are unused, I believe it would be more consistent to emit a warning in set.rb when a block passed to initialize won't be used.
marcandre
Metadata
Metadata
Assignees
Labels
No labels