Project

General

Profile

Actions

Bug #21558

closed

Regexp.union with multiple regexps returns a non-shareable object (should be shareable if possible)

Added by niku (niku _) 7 days ago. Updated 5 days ago.

Status:
Feedback
Assignee:
-
Target version:
-
ruby -v:
ruby 3.5.0dev (2025-08-30T18:24:25Z master 5c7dfe85a1) +PRISM [arm64-darwin24]
[ruby-core:123141]

Description

Regexp.union returns a non-shareable object when given multiple Regex arguments. Is this expected behavior?
It would be preferable if the resulting Regexp were shareable, since single-argument Regexp.union does produce a shareable object.

irb(main):001> a = /a/
=> /a/
irb(main):002> b = Regexp.union(a)
=> /a/
irb(main):003> c = Regexp.union(a, a)
=> /(?-mix:a)|(?-mix:a)/
irb(main):004> Ractor.shareable?(a)
=> true
irb(main):005> Ractor.shareable?(b)
=> true
irb(main):006> Ractor.shareable?(c)
=> false

Related issues 2 (1 open1 closed)

Related to Ruby - Feature #17256: Freeze all Regexp objectsClosedmatz (Yukihiro Matsumoto)Actions
Related to Ruby - Feature #8948: Frozen regexAssignedEregon (Benoit Daloze)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0