[go: nahoru, domu]

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

Fix incorrect parent class assignment for Object and BasicObject #2175

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

st0012
Copy link
Member
@st0012 st0012 commented Jun 12, 2024

Motivation

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.

The issue was discovered when pairing with @Morriar on #1046 as Object are displayed in Object'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

@st0012 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 st0012 self-assigned this Jun 12, 2024
@st0012 st0012 requested a review from a team as a code owner June 12, 2024 17:18
@st0012 st0012 requested review from andyw8 and vinistock June 12, 2024 17:18
@@ -136,6 +136,9 @@ class Module < Namespace
class Class < Namespace
extend T::Sig

OBJECT_NESTING = T.let(["Object"].freeze, T::Array[String])
Copy link
Member Author
@st0012 st0012 Jun 12, 2024

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

@st0012 st0012 force-pushed the fix-incorrect-top-level-object-class-resolution branch from 7b65930 to c897686 Compare June 12, 2024 17:59
@st0012 st0012 force-pushed the fix-incorrect-top-level-object-class-resolution branch from c897686 to 7aa9eb8 Compare June 12, 2024 18:34
@st0012 st0012 requested a review from vinistock June 12, 2024 18:34
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 st0012 force-pushed the fix-incorrect-top-level-object-class-resolution branch from 7aa9eb8 to 39faf38 Compare June 12, 2024 19:05
@st0012 st0012 enabled auto-merge (squash) June 12, 2024 19:05
@st0012 st0012 disabled auto-merge June 12, 2024 20:11
@st0012 st0012 merged commit 75de0ad into main Jun 12, 2024
32 checks passed
@st0012 st0012 deleted the fix-incorrect-top-level-object-class-resolution branch June 12, 2024 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants