Skip to content

Aliased global variables should know their called name #9177

@headius

Description

@headius

When aliasing a global variable, accesses that produce warnings or errors should reflect the aliased name.

For example, the $/ variable in CRuby:

$ cx 4 ruby -v -e 'alias $foo $/; $foo = "1"'
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [arm64-darwin24]
-e:1: warning: non-nil '$foo' is deprecated
$ ruby -v -e 'alias $foo $/; $foo = "1"'     
jruby 10.1.0.0-SNAPSHOT (4.0.0) 2026-01-13 8534401b79 OpenJDK 64-Bit Server VM 21.0.8+9-LTS on 21.0.8+9-LTS +indy +jit [arm64-darwin]
-e:1: warning: 'non-nil '$/'' is deprecated

This leads to at least one warning in the Ruby 4.0.0 tests:

  1) Failure:
TestString#test_rs [/Users/headius/work/jruby/test/mri/ruby/test_string.rb:2908]:
expected: /\$分行/
actual: "".

The problem here is that our global variable aliasing logic just assigns the old GlobalVariable object to an additional name in the globals table, but that object holds onto its original name. The logic for accessing a global variable needs to also pass through the accessed name so it can be used in warnings and errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions