From: marcandre-ruby-core@...
Date: 2020-12-16T18:58:23+00:00
Subject: [ruby-core:101474] [Ruby master Feature#17397] shareable_literal_constant should check at runtime, not at parse time

Issue #17397 has been updated by marcandre (Marc-Andre Lafortune).


Ideally, the following would also be accepted:

```ruby
# shareable_constant_value: literal

Map = {
  int: Integer,
  str: String,
  # ...
}
Map.frozen # => true
```

Literals that are arguments to method calls should not be frozen:

```ruby
# shareable_constant_value: literal

def check(arg)
  p arg.frozen?
  arg.freeze
end

X = check([1,2,3]) # => prints false
Y = [1] + [2] # => error
```


----------------------------------------
Feature #17397: shareable_literal_constant should check at runtime, not at parse time
https://bugs.ruby-lang.org/issues/17397#change-89251

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
----------------------------------------
I think `shareable_constant_value: literal` is too strict because it has too crude checks at parse time.

I wish the following code would parse and run:

```ruby
# shareable_constant_value: literal

class Foo < RuntimeError
end

# Similar code, but does not parse:
Bar = Class.new(RuntimeError) # => unshareable expression

Baz = Ractor.make_shareable(anything_here) # => unshareable expression

Qux = Set[1, 2, 3].freeze # => unshareable expression
```

Could we instead raise some sort of RuntimeError when an assignment is made that is not shareable?



-- 
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>