Skip to content
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

Different Regexp behavior from MRI #2905

Closed
nirvdrum opened this Issue May 1, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@nirvdrum
Copy link
Contributor

commented May 1, 2015

It looks like somewhere between 1.9.3 and 2.2.2, MRI changed its behavior around overriding String#=~. JRuby 9.0.0.0.pre2 special-cases this behavior in:

https://github.com/jruby/jruby/blob/9.0.0.0.pre2/core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java#L577-L579

It looks like the correct behavior is to always do a dispatch to =~ to pick up any overrides.

E.g.,

MRI 2.2.2:

> ruby -v -e 'class String; def =~(regexp); :weird_value; end; end; p "a" =~ /./'
-e:1: warning: method redefined; discarding old =~
:weird_value

JRuby 9.0.0.0.pre2:

> bin/jruby -v -e 'class String; def =~(regexp); :weird_value; end; end; p "a" =~ /./'
jruby 9.0.0.0-SNAPSHOT (2.2.2) 2015-04-30 ef1fc91 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-amd64]
0

@nirvdrum nirvdrum added the JRuby 9000 label May 1, 2015

@nirvdrum

This comment has been minimized.

Copy link
Contributor Author

commented May 1, 2015

Interestingly, MRI 1.9.3 prints the same warning, but then prints the match index.

@headius

This comment has been minimized.

Copy link
Member

commented May 4, 2015

Might just be simplest to make all matches dyncall; caching and indy will make up the difference between this and the direct call.

@headius

This comment has been minimized.

Copy link
Member

commented May 5, 2015

Oops, forgot to tag the commit. This should be fixed on master in 8d67e58.

@headius headius closed this May 5, 2015

@headius headius added this to the JRuby 9.0.0.0.rc1 milestone May 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.