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

Add spec confirming Runtime error when a class variable is overtaken #888

Merged
merged 4 commits into from
Oct 28, 2021

Conversation

aslam
Copy link

@aslam aslam commented Oct 26, 2021

Ref. #823

When a class variable is overtaken by the same definition in an ancestor class/module, a RuntimeError is now raised (previously, it only issued a warning in verbose mode). Additionally, accessing a class variable from the top-level scope is now a RuntimeError. [Bug #14541]

it "raises Runtime error when a defined class variable is overtaken" do
-> do
eval <<-CODE
@@cvar_a = :new_val
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks accessing a class variable from the toplevel (i.e., not under some class/module), but not overtaking itself, which is something different: setting a class var in a parent class when it's already defined in a child class.
Could you try to add a separate example (it) for that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍, initially I was reading the description as "it should raise an error when the parent class tries to define the class variable already defined by the child".

Added the needed test.

- also update test definitions to better describe the test
@aslam aslam requested a review from eregon October 27, 2021 20:26
Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eregon eregon merged commit 7d97955 into ruby:master Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants