Project

General

Profile

Actions

Bug #20033

closed

`/#{''}(?<lvar>)/ =~ s` looks like a dynamic regexp match but assigns to local variable

Added by tompng (tomoya ishida) 7 months ago. Updated 7 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0dev (2023-11-30T16:23:25Z master d048bae96b) [x86_64-linux]
[ruby-core:115563]

Description

I expect all of these code not to assign to lvar because all regexp looks like embedded dynamic regexp.

/#{''}(?<lvar>)/ =~ '' # assings to lvar

/#{"#{''}"}(?<lvar>)/ =~ '' # does not assign to lvar

/#{<<A}(?<lvar>)/ =~ '' # assigns to lvar
  string
A

/#{<<A}(?<lvar>)/ =~ '' # does not assign to lvar
  #{'string'}
A

I think /#{'a'}/ can be a DREGX because for string, "#{'a'}#{'b'}" is DSTR (DSTR@1:0-1:14 "ab" nil nil).

Updated by Eregon (Benoit Daloze) 7 months ago

+1, it should only be static regexp literals which assign variables (= without #{}), that's much simpler for everyone to understand.
The current situation feels like mixing parsing and compilation/optimization in the parser.

Actions #3

Updated by nobu (Nobuyoshi Nakada) 7 months ago

  • Status changed from Open to Closed

Applied in changeset git|a607d62d8c5786087916413c369dbde0c62db573.


[Bug #20033] Dynamic regexp should not assign captures

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0