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

Regexp.last_match(Symbol) is not supported #2179

Closed
amyspark opened this issue Dec 7, 2020 · 3 comments
Closed

Regexp.last_match(Symbol) is not supported #2179

amyspark opened this issue Dec 7, 2020 · 3 comments
Assignees
Milestone

Comments

@amyspark
Copy link

amyspark commented Dec 7, 2020

The Regexp class does not parse or accept queries for named captures. This is a feature introduced in MRI 1.9.

This currently breaks Jekyll 4.1.1 in truffleruby.

MWE (from irb):

irb(main):006:0> /(?:<test>[A-Z]+.*)/.match? "TEST123"
=> false
irb(main):007:0> /(?:[A-Z]+.*)/.match? "TEST123"
=> true
irb(main):008:0> Regexp.last_match :test
Traceback (most recent call last):
       12: from /home/amalia/.rbenv/versions/truffleruby-20.3.0/bin/irb:37:in `<main>'
       11: from <internal:core> core/kernel.rb:401:in `load'
       10: from <internal:core> core/kernel.rb:401:in `load'
        9: from /home/amalia/.rbenv/versions/truffleruby-20.3.0/lib/gems/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
        8: from <internal:core> core/throw_catch.rb:36:in `catch'
        7: from <internal:core> core/throw_catch.rb:36:in `catch'
        6: from <internal:core> core/kernel.rb:438:in `loop'
        5: from <internal:core> core/kernel.rb:325:in `eval'
        4: from (irb):8
        3: from <internal:core> core/regexp.rb:83:in `last_match'
        2: from <internal:core> core/type.rb:186:in `rb_to_int_fallback'
        1: from <internal:core> core/type.rb:277:in `convert_type'
TypeError (no implicit conversion of Symbol into Integer)

Using truffleruby 20.3.0 from rbenv.

@eregon
Copy link
Member

eregon commented Dec 7, 2020

I think this only applies to Regexp.last_match with a Symbol argument, otherwise named captures work fine:

$ ruby -e '/(?<test>[A-Z]+.*)/.match "TEST123"; p $~[:test]; p Regexp.last_match :test'
"TEST123"
<internal:core> core/type.rb:277:in `convert_type': no implicit conversion of Symbol into Integer (TypeError)
	from <internal:core> core/type.rb:186:in `rb_to_int_fallback'
	from <internal:core> core/regexp.rb:83:in `last_match'
	from -e:1:in `<main>'

There are several issues in the example above, match? won't set $? and the groups are non-capturing ((?:).

@eregon eregon changed the title Regexp does not take named captures Regexp.last_match(Symbol) is not supported Dec 7, 2020
@amyspark
Copy link
Author

amyspark commented Dec 7, 2020

I think this only applies to Regexp.last_match with a Symbol argument, otherwise named captures work fine:

$ ruby -e '/(?<test>[A-Z]+.*)/.match "TEST123"; p $~[:test]; p Regexp.last_match :test'
"TEST123"
<internal:core> core/type.rb:277:in `convert_type': no implicit conversion of Symbol into Integer (TypeError)
	from <internal:core> core/type.rb:186:in `rb_to_int_fallback'
	from <internal:core> core/regexp.rb:83:in `last_match'
	from -e:1:in `<main>'

There are several issues in the example above, match? won't set $? and the groups are non-capturing ((?:).

Apologies, I just wanted a minimal test case to show you the stacktrace from Regexp. The actual one came from Jekyll and was way bigger.

@bjfish bjfish self-assigned this Dec 9, 2020
@bjfish
Copy link
Contributor

bjfish commented Dec 10, 2020

This is fixed at: cda1364

@bjfish bjfish closed this as completed Dec 10, 2020
@bjfish bjfish added this to the 21.1.0 milestone Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants