Skip to content

Avoid inconsistent implicit toString on potential string subtypes#21318

Open
ginsbach wants to merge 1 commit intomainfrom
ginsbach/fix-tostring-parameterised-modules
Open

Avoid inconsistent implicit toString on potential string subtypes#21318
ginsbach wants to merge 1 commit intomainfrom
ginsbach/fix-tostring-parameterised-modules

Conversation

@ginsbach
Copy link
Contributor

@ginsbach ginsbach commented Feb 12, 2026

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".

See also #21306.

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".
@ginsbach ginsbach marked this pull request as ready for review February 18, 2026 14:20
@ginsbach ginsbach requested a review from a team as a code owner February 18, 2026 14:20
Copilot AI review requested due to automatic review settings February 18, 2026 14:20
@ginsbach ginsbach added the no-change-note-required This PR does not need a change note label Feb 18, 2026
@ginsbach ginsbach requested a review from hvitved February 18, 2026 14:21
* This is the absolute path of the container.
*/
string toString() { result = this.getAbsolutePath() }
string toString() { result = super.toString() }
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 the ContainerBase signature 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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DataFlow Library no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments