Skip to content

Conversation

@thdaraujo
Copy link
Contributor

(related to #2667)

The error can be seen in CRuby with parse.y enabled:

ruby --parser=parse.y -e "p /Ȃ/e.encoding"

#=> -e:1: regexp encoding option 'e' differs from source encoding 'UTF-8'
ruby: compile error (SyntaxError)

It could also be seen on Ruby 3.4.7 with Prism enabled:

ruby -e "p /Ȃ/e.encoding"
-e: -e:1: syntax error found (SyntaxError)
#=> > 1 | p /Ȃ/e.encoding
        |       ^ regexp encoding option 'e' differs from source encoding 'UTF-8'

And by parsing directly, you get the error too:

bin/parse -e "p /Ȃ/e.encoding"

Errors:
[#<Prism::ParseError @type=:regexp_encoding_option_mismatch @message="regexp encoding option 'e' differs from source encoding 'UTF-8'" @location=#<Prism::Location @start_offset=7 @length=1 start_line=1> @level=:syntax>]

Looking at the CRuby and Prism implementations, both are doing the same checks.

But the CRuby code is only enabled for Ripper (with the #ifndef RIPPER).

So maybe the problem is that Ruby + Prism is raising the Syntax error, but it should only be raised when using Ripper, and not during normal execution? But that would contradict the original issue description, which expects the syntax error to be raised.

I might be missing some context here about what the right behaviour should be, but I went ahead and added some tests to make sure the current behavior is the expected one. Hope this makes sense!

Thanks!

result = Prism.parse('/Ȃ/u')
assert_empty result.errors
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this test be added to prism/encoding/regular_expression_encoding_test.rb instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine here.

@Earlopain
Copy link
Collaborator

Looks like this may have already been implemented in #2486. It's a bit weird since the issue was openend a month after that PR got merged.

Ripper shouldn't matter here, what's important is that ruby -c test.rb and ruby --parser=parse.y -c test.rb report the same thing (I know very little about how the original parser is actually implemented). prism and parse.y seem to agree, so all seems good?

@thdaraujo
Copy link
Contributor Author

@Earlopain yeah that's what I was thinking too. Maybe we can close the issue.

Do we care about adding these tests, or should I just close this PR?

Thanks!

@kddnewton
Copy link
Collaborator

Hmm... it would appear it's as you say, and the original can be closed

@kddnewton kddnewton merged commit ec4178b into ruby:main Nov 20, 2025
64 checks passed
@thdaraujo thdaraujo deleted the ta/add-test-to-regexp-encoding-mismatch-error-2667 branch November 20, 2025 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants