-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: only exclude unoverridden virtual functions in inheritance-graph #2915
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: only exclude unoverridden virtual functions in inheritance-graph #2915
Conversation
a7bc8a0 to
178e07c
Compare
dguido
left a comment
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.
Code Review Summary
Reviewed file: slither/printers/inheritance/inheritance_graph.py
Change Analysis
The change modifies the filter condition for public/external functions in the inheritance graph:
- and not f.is_virtual
+ and not (f.is_virtual and not f.overridden_by) # Exclude unoverridden virtual functionsBefore: All virtual functions were excluded from the inheritance graph output.
After: Only virtual functions that have no overrides are excluded. Virtual functions that ARE overridden by derived contracts are now shown.
Verification
-
Logic correctness: The new condition
(f.is_virtual and not f.overridden_by)correctly identifies virtual functions without any derived implementations. Theoverridden_byproperty returns an empty list[]when no overrides exist, and empty lists are falsy in Python, sonot f.overridden_byworks correctly. -
API usage: The
overridden_byattribute is properly typed aslist[FunctionContract]and always initialized to[]inslither/core/declarations/function.py:128, so it will never beNone. -
Tests pass: Ran
test_inheritance_printerandtest_virtual_overrides- all pass. -
Linting:
ruff checkpasses with no issues. -
Comment quality: The inline comment is appropriate and explains the filtering behavior.
Observations
-
The
private_functionsfilter (lines 130-137) does not and never did filter byis_virtual, so this change doesn't introduce an inconsistency. -
This addresses part of issue #2150 by making the inheritance graph output more complete while still excluding pure interface methods (virtual functions with no implementation).
Approved. Clean, minimal change that improves the inheritance graph output.
Bulk PR Review SummaryResearch Findings
Test Status
Code Review (Pedantic Level)
Merge ReadinessReady to merge. Clean, minimal change that improves inheritance graph output by showing virtual functions that have implementations while still hiding pure interface methods. No regressions introduced. |
178e07c to
55b98bf
Compare
Previously, all virtual functions were excluded from the inheritance-graph printer output. This change refines the logic to only exclude virtual functions that are not overridden by any derived contract. Virtual functions that ARE overridden are now included, as they represent actual implementations being used in the codebase. Partially addresses crytic#2150
55b98bf to
955bac5
Compare
Code reviewFound 1 issue:
slither/slither/printers/inheritance/inheritance_graph.py Lines 124 to 126 in dd00ad3
The comment 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
The comment "# Exclude unoverridden virtual functions" directly restates what the boolean expression already expresses through property names. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Summary
Refines the inheritance-graph printer to only exclude virtual functions that are not overridden, instead of excluding all virtual functions.
Problem
The current logic excludes ALL virtual functions from the inheritance graph:
This is overly aggressive - virtual functions that ARE overridden by derived contracts represent actual implementations being used and should be shown.
Solution
Changed the condition to only exclude virtual functions that have no overrides:
This means:
Example
Before: Both
fooandbarexcluded from Base nodeAfter: Only
fooexcluded,baris shownPartially addresses #2150