[ruby-core:96012] [Ruby master Feature#16377] Regexp literals should be frozen

From: jean.boussier@...
Date: 2019-11-28 06:37:07 UTC
List: ruby-core #96012
Issue #16377 has been updated by byroot (Jean Boussier).


Apparently it's a duplicate of https://bugs.ruby-lang.org/issues/8948

----------------------------------------
Feature #16377: Regexp literals should be frozen
https://bugs.ruby-lang.org/issues/16377#change-82850

* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The following script:

```ruby
def mutate
  re = /foo/
  state = re.instance_variable_get(:@state)
  re.instance_variable_set(:@state, state.to_i + 1)
  state
end

3.times do
  p mutate
end
```

Output this:

```
nil
1
2
```

IMHO, you shouldn't be able to mutate an unduplicated literal.

GitHub pull request: https://github.com/ruby/ruby/pull/2705



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next