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

Clarify spec error for Regexp.last_match #2621

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

herwinw
Copy link
Member

@herwinw herwinw commented Feb 26, 2025

The issue is not related to errors bubbling up, but simply because we set our regexp globals as block local, which should be treated as scope local.

A simple example:

/foo/ =~ 'foobar'
-> { p Regexp.last_match }.call

This prints the MatchData object in MRI, but Natalie prints a nil.

We have the same issue the other way around:

-> { /foo/ =~ 'foobar' }.call
p Regexp.last_match

Rewrite the failing specs into a form that works that is closer to the original spec.

There is some logic conserning caller scopes and outer blocks in the lookups, but that might have to be redone. This issue is not limited to this spec, but it occurs everywhere we use any global references to regex results.

The issue is not related to errors bubbling up, but simply because we
set our regexp globals as block local, which should be treated as scope
local.

A simple example:
```ruby
/foo/ =~ 'foobar'
-> { p Regexp.last_match }.call
```
This prints the MatchData object in MRI, but Natalie prints a nil.

We have the same issue the other way around:
```ruby
-> { /foo/ =~ 'foobar' }.call
p Regexp.last_match
```

Rewrite the failing specs into a form that works that is closer to the
original spec.

There is some logic conserning caller scopes and outer blocks in the
lookups, but that might have to be redone. This issue is not limited to
this spec, but it occurs everywhere we use any global references to
regex results.
@herwinw herwinw merged commit 30451cb into natalie-lang:master Feb 26, 2025
19 checks passed
@herwinw herwinw deleted the regexp_last_match branch February 26, 2025 14:33
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.

2 participants