-
Notifications
You must be signed in to change notification settings - Fork 178
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
Fix incorrect parent class assignment for Object and BasicObject #2175
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
st0012
added
bugfix
This PR will fix an existing bug
server
This pull request should be included in the server gem's release notes
labels
Jun 12, 2024
st0012
commented
Jun 12, 2024
@@ -136,6 +136,9 @@ class Module < Namespace | |||
class Class < Namespace | |||
extend T::Sig | |||
|
|||
OBJECT_NESTING = T.let(["Object"].freeze, T::Array[String]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: using arrays in case statement will allocate a new array each time the case statement is hit.
Script:
a = ["Object"]
b = ["Object"]
c = []
CONST = ["Object"]
def match_with_const(x)
case x
when CONST
puts "Matched"
end
end
def match_with_array(x)
case x
when ["Object"]
puts "Matched"
end
end
puts "Arrays count before match_with_const: #{ObjectSpace.count_objects[:T_ARRAY]}"
match_with_const a
match_with_const b
match_with_const c
puts "Arrays count after match_with_const: #{ObjectSpace.count_objects[:T_ARRAY]}"
puts "Arrays count before match_with_array: #{ObjectSpace.count_objects[:T_ARRAY]}"
match_with_array a
match_with_array b
match_with_array c
puts "Arrays count after match_with_array: #{ObjectSpace.count_objects[:T_ARRAY]}"
Output:
Arrays count before match_with_const: 1752
Matched
Matched
Arrays count after match_with_const: 1752
Arrays count before match_with_array: 1752
Matched
Matched
Arrays count after match_with_array: 1755
andyw8
reviewed
Jun 12, 2024
st0012
force-pushed
the
fix-incorrect-top-level-object-class-resolution
branch
from
June 12, 2024 17:59
7b65930
to
c897686
Compare
andyw8
reviewed
Jun 12, 2024
andyw8
reviewed
Jun 12, 2024
andyw8
approved these changes
Jun 12, 2024
vinistock
reviewed
Jun 12, 2024
st0012
force-pushed
the
fix-incorrect-top-level-object-class-resolution
branch
from
June 12, 2024 18:34
c897686
to
7aa9eb8
Compare
vinistock
approved these changes
Jun 12, 2024
When the Object and BasicObject classes are reopened, their parent class should remain `BasicObject` and `nil` respectively. This change fixes the current behaviour where the parent class is incorrectly set to `Object`.
st0012
force-pushed
the
fix-incorrect-top-level-object-class-resolution
branch
from
June 12, 2024 19:05
7aa9eb8
to
39faf38
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When the Object and BasicObject classes are reopened, their parent class should remain
BasicObject
andnil
respectively. This change fixes the current behaviour where the parent class is incorrectly set toObject
.The issue was discovered when pairing with @Morriar on #1046 as
Object
are displayed inObject
's supertypes list too.Implementation
We should check these 2 special cases before deciding the parent class.
Automated Tests
I added 4 new test cases for it.
Manual Tests