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

The & operator doesn't work with quoted symbols #5066

Closed
pcarlisle opened this Issue Feb 28, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@pcarlisle

pcarlisle commented Feb 28, 2018

Environment

jruby 9.1.16.0 (2.3.3) 2018-02-21 8f3f95a Java HotSpot(TM) 64-Bit Server VM 25.162-b12 on 1.8.0_162-b12 +jit [linux-x86_64]

Linux 4.14.14-1-ARCH #1 SMP PREEMPT Fri Jan 19 18:42:04 UTC 2018 x86_64 GNU/Linux

Expected Behavior

% ruby -v
ruby 2.3.6p384 (2017-12-14 revision 61254) [x86_64-linux]
% irb
irb(main):001:0> (1..3).reduce(&:'+')
=> 6
irb(main):002:0> (1..3).map(&:'to_s')
=> ["1", "2", "3"]
irb(main):003:0> 

Actual Behavior

irb(main):006:0> (1..3).reduce(&:+)
=> 6
irb(main):007:0> (1..3).reduce(&:'+')
NoMethodError: undefined method `+' for 1:Fixnum
	from org/jruby/RubyRange.java:495:in `each'
	from org/jruby/RubyEnumerable.java:931:in `inject'
	from (irb):7:in `<eval>'
	from org/jruby/RubyKernel.java:995:in `eval'
	from org/jruby/RubyKernel.java:1316:in `loop'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from /home/patrick/.rbenv/versions/jruby-9.1.16.0/bin/irb:13:in `<main>'
irb(main):008:0> method = :'+'
=> :+
irb(main):009:0> (1..3).reduce(&method)
=> 6

irb(main):012:0> (1..3).map(&:'to_s')
NoMethodError: undefined method `to_s' for 1:Fixnum
	from org/jruby/RubyRange.java:495:in `each'
	from org/jruby/RubyEnumerable.java:830:in `map'
	from (irb):12:in `<eval>'
	from org/jruby/RubyKernel.java:995:in `eval'
	from org/jruby/RubyKernel.java:1316:in `loop'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from org/jruby/RubyKernel.java:1138:in `catch'
	from /home/patrick/.rbenv/versions/jruby-9.1.16.0/bin/irb:13:in `<main>'
@pcarlisle

This comment has been minimized.

pcarlisle commented Feb 28, 2018

Oh I tried searching before but now just found #3880 and related and this is probably the same

@headius

This comment has been minimized.

Member

headius commented Feb 28, 2018

Wow that's pretty weird. I'd expect this to work since the string part doesn't contain anything weird.

This, like #3880, is probably fixed by @enebo's almost-complete rework of strings, symbols, and identifiers (for 9.2).

Not sure if there's a workaround. I am surprised this doesn't work.

@headius headius added this to the JRuby 9.2.0.0 milestone Feb 28, 2018

@pcarlisle

This comment has been minimized.

pcarlisle commented Feb 28, 2018

The workaround seems to be saving the quoted symbol to a variable and calling with that (which maybe suggests it's not an encoding issue)

@enebo

This comment has been minimized.

Member

enebo commented Feb 28, 2018

fwiw bytelist_love branch does work now but I also find this super weird that it is broken. It is already ascii and a symbol. Even with utf-8 as default this encoding should be US-ASCII.

enebo added a commit that referenced this issue Feb 28, 2018

Fixes #5066. The & operator doesn't work with quoted symbols.
We were building a String with the entire bytelist buffer for symbols instead
of proper bounds.  We only saw this issue because :'to_s' goes through Ruby
String processing before being made into a Symbol.  Sort of a weird combo
but it is possible this bad code in Symbol.getName() could be causing other
issues?

[Note: this will only be effective fix for 9.1.  For 9.2 this is already fixed
because we have switched to a completely different way of handling encoded
identifiers.]

@enebo enebo modified the milestones: JRuby 9.2.0.0, JRuby 9.1.17.0 Feb 28, 2018

@enebo

This comment has been minimized.

Member

enebo commented Feb 28, 2018

Yeah this was just another case of pretending unsafeBytes() has begin of 0 and .length or realSize(). Almost hard to imagine any of these bugs could still exist...And bytelist_love is totally different now so this code I fixed does not exist there (and this works fine there).

@enebo enebo closed this Feb 28, 2018

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