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: C variables should never show up in Ancestors tree #1217

Conversation

flavorjones
Copy link
Collaborator

@flavorjones flavorjones commented Nov 28, 2024

If a NormalClass's superclass is a C variable ("enclosure"), then update the superclass to point to the RDoc::NormalClass.

This is done in a single pass after all files have been parsed.

Fixes #1205.

Before:

image

After:

image

@s.resolve_c_references

# now the ancestor tree correctly references the NormalClass objects
assert_equal(parent, @s.classes_hash['Child'].superclass)
Copy link
Member

Choose a reason for hiding this comment

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

(#superclass can return either string or RDoc::NormalClass really hurts my brain 🙈)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😬

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And of course the bug in #1221 is related to this confusion. 🤦

If a NormalClass's superclass is a C enclosure, then update the
superclass to point to the RDoc::NormalClass.

This is done in a single pass after all files have been parsed.

Fixes ruby#1205.
@flavorjones flavorjones force-pushed the flavorjones-fix-up-c-variables-in-ancestor-tree branch from ae631cb to 8013d3d Compare November 30, 2024 03:27
@flavorjones flavorjones requested a review from st0012 November 30, 2024 03:28
@st0012 st0012 added the bug label Nov 30, 2024
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@st0012 st0012 merged commit 1ecd958 into ruby:master Nov 30, 2024
26 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 30, 2024
(ruby/rdoc#1217)

If a NormalClass's superclass is a C enclosure, then update the
superclass to point to the RDoc::NormalClass.

This is done in a single pass after all files have been parsed.

Fixes ruby/rdoc#1205.

ruby/rdoc@1ecd9581b1
@flavorjones flavorjones deleted the flavorjones-fix-up-c-variables-in-ancestor-tree branch November 30, 2024 14:19
flavorjones added a commit to flavorjones/rdoc that referenced this pull request Dec 2, 2024
It is necessary for ClassModule's instance variable @superclass to
always be a String (or nil) so that the class can be saved with
`#marshal_dump` and loaded with `#marshal_load`.

However, there's no type checking being done, which allows a bug like
the one reported in ruby#1221 (which was introduced in ruby#1217) that sets
superclass to a ClassModule. That bug requires:

- setting a superclass to a NormalClass
- marshal_save
- marshal_load (which raises an exception)

With this change, passing a ClassModule to ClassModule#superclass= is
explicitly allowed by saving the full name of the ClassModule in the
@superclass instance variable.
st0012 pushed a commit that referenced this pull request Dec 2, 2024
It is necessary for ClassModule's instance variable @superclass to
always be a String (or nil) so that the class can be saved with
`#marshal_dump` and loaded with `#marshal_load`.

However, there's no type checking being done, which allows a bug like
the one reported in #1221 (which was introduced in #1217) that sets
superclass to a ClassModule. That bug requires:

- setting a superclass to a NormalClass
- marshal_save
- marshal_load (which raises an exception)

With this change, passing a ClassModule to ClassModule#superclass= is
explicitly allowed by saving the full name of the ClassModule in the
@superclass instance variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

In v6.8.1, C extension objects "Ancestors" list shows C symbol name instead of class name
2 participants