Project

General

Profile

Bug #15437

正規表現の名前付きキャプチャでASCII以外の大文字で定義したクラスが上書きされる

Added by hanachin (Seiei Miyagi) 3 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 2.6.0rc2 (2018-12-15 trunk 66408) [x86_64-linux]
[ruby-dev:50719]

Description

ASCIIの大文字で定義したクラスは正規表現の名前付きキャプチャで上書きされませんが、ASCII以外の大文字で定義したクラスは上書きされてしまうようです。
これは意図的ですか?

# rewrite_constant_by_named_capture.rb
class C
end

/(?<C>C)/ =~ "C"

p C

class 𝐂
end

/(?<𝐂>𝐂)/ =~ "𝐂"

p 𝐂

C.new
𝐂.new
% ruby -v rewrite_constant_by_named_capture.rb
ruby 2.6.0rc2 (2018-12-15 trunk 66408) [x86_64-linux]
C
rewrite_constant_by_named_capture.rb:11: warning: already initialized constant 𝐂
rewrite_constant_by_named_capture.rb:8: warning: previous definition of 𝐂 was here
"𝐂"
Traceback (most recent call last):
rewrite_constant_by_named_capture.rb:16:in `<main>': undefined method `new' for "𝐂":String (NoMethodError)
Did you mean?  next

Associated revisions

Revision f89238ec
Added by nobu (Nobuyoshi Nakada) 3 months ago

parse.y: ignore constant name captures

  • parse.y (reg_named_capture_assign_iter): ignore non-local name captures, including non-ASCII constant names. [ruby-dev:50719] [Bug #15437]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 66463
Added by nobu (Nobuyoshi Nakada) 3 months ago

parse.y: ignore constant name captures

  • parse.y (reg_named_capture_assign_iter): ignore non-local name captures, including non-ASCII constant names. [ruby-dev:50719] [Bug #15437]

Revision 66463
Added by nobu (Nobuyoshi Nakada) 3 months ago

parse.y: ignore constant name captures

  • parse.y (reg_named_capture_assign_iter): ignore non-local name captures, including non-ASCII constant names. [ruby-dev:50719] [Bug #15437]

History

#1

Updated by naruse (Yui NARUSE) 3 months ago

  • Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN to 2.4: DONTNEED, 2.5: DONTNEED
  • Target version set to 2.6
#2

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r66463.


parse.y: ignore constant name captures

  • parse.y (reg_named_capture_assign_iter): ignore non-local name captures, including non-ASCII constant names. [ruby-dev:50719] [Bug #15437]
#3

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Description updated (diff)

Also available in: Atom PDF