Avoid inconsistent implicit toString on potential string subtypes#21318
Open
Avoid inconsistent implicit toString on potential string subtypes#21318
toString on potential string subtypes#21318Conversation
Fix cases where the compiler cannot prove types don't extend string: 1. FileSystem.qll: Add toString() to ContainerBase signature. The instantiation sites already provide toString(), so no changes needed there. Container.toString() now delegates to super.toString(). No behaviour change. 2. DataFlowImplCommon.qll: Content.toString() now delegates to super.toString() instead of returning the literal "Content". This is a behaviour change: Content now displays its actual description (e.g. field names) rather than the generic "Content".
hvitved
reviewed
Feb 18, 2026
| * This is the absolute path of the container. | ||
| */ | ||
| string toString() { result = this.getAbsolutePath() } | ||
| string toString() { result = super.toString() } |
Contributor
There was a problem hiding this comment.
This adds the possibility for languages to use different toStrings, which I think we'll want to avoid. Does it make a difference if we change class Container instanceof Input::ContainerBase to class Container extends ContainerBaseFinal where private final class ContainerBaseFinal = Input::ContainerBase?
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes inconsistent implicit toString behavior on types that might extend string by ensuring explicit toString() definitions are provided in signatures and properly delegated.
Changes:
- Added
toString()method to theContainerBasesignature in FileSystem.qll - Changed Container.toString() to delegate to super.toString() instead of directly calling getAbsolutePath()
- Changed Content.toString() in DataFlowImplCommon.qll to delegate to super.toString() instead of returning the literal "Content"
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| shared/util/codeql/util/FileSystem.qll | Adds toString() to ContainerBase signature and updates Container class to delegate to super.toString() |
| shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll | Updates Content class to delegate toString() to super instead of returning literal "Content" |
This file contains hidden or 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
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.
Fix cases where the compiler cannot prove types don't extend string:
FileSystem.qll: Add
toString()to ContainerBase signature. The instantiation sites already provide toString(), so no changes needed there.Container.toString()now delegates tosuper.toString(). No behaviour change.DataFlowImplCommon.qll:
Content.toString()now delegates tosuper.toString()instead of returning the literal"Content". This is a behaviour change: Content now displays its actual description (e.g. field names) rather than the generic"Content".See also #21306.