Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uppercase instance or class variables #14093

Open
HertzDevil opened this issue Dec 14, 2023 · 1 comment
Open

Uppercase instance or class variables #14093

HertzDevil opened this issue Dec 14, 2023 · 1 comment

Comments

@HertzDevil
Copy link
Contributor

It is in fact possible to define instance or class variables whose name starts with an uppercase letter:

class Foo
  @A = 1
  @@B = 2

  def foo
    @A + @@B
  end
end

Foo.new.foo # => 3

The same holds for Ruby as well. However, this is causing codegen problems for us, such as in #7865.

Should we deprecate this syntax or do we accept it as valid?

@straight-shoota
Copy link
Member

So the codegen issue is that class vars and constants of the same name would result in the same init function?
@@A and A both use a function called something like Namespace:A:init as initializer.
I suppose we could prevent this collision by introducing disambiguation (e.g. Namespace:const_A:init, Namespace:var_A:init).

But I don't see much value in allowing uppercase class or instance variables. I think it's pretty unexpected that this is even possible.
Probably nobody will miss this, so I'd be happy to remove this syntax.
To be sure on this, we can start deprecating it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants