Skip to content

Query Console does not show elements without toString() / Some elements have no toString() #5290

@Marcono1234

Description

@Marcono1234

Relates to #2397, #2538

The Query Console does not show elements whose toString() result is none() and for multiple languages there are elements without a toString() result; this can make debugging rather difficult.
(I have not tested whether this affects the VSCode extension as well)

I am not familiar with the CodeQL classes for the languages other than Java, so the following queries might be flawed.
For all affected languages, including the element whose toString() is checked in the select clause makes the query yield no results.

C/C++ (affected)

import cpp

from ElementBase e, boolean hasToString
where
  if exists(e.toString()) then hasToString = true else hasToString = false
  and hasToString = false
select e.getAPrimaryQlClass(), hasToString

Query Console link

C# (affected)

import csharp

from Element e, boolean hasToString, boolean hasLocation
where
  if exists(e.toString()) then hasToString = true else hasToString = false
  and if exists(e.getLocation()) then hasLocation = true else hasLocation = false
  and hasToString = false
select e.getAPrimaryQlClass(), hasToString, hasLocation

Query Console link

Go

Not sure if affected; there are no demo projects to scan.

import go

from Locatable l, boolean hasToString, boolean hasLocation
where
  if exists(l.toString()) then hasToString = true else hasToString = false
  and if exists(l.getLocation()) then hasLocation = true else hasLocation = false
  and hasToString = false
select hasToString, hasLocation

Java (affected)

See also #5289

import java

from Top top, boolean hasToString, boolean hasLocation
where
  if exists(top.toString()) then hasToString = true else hasToString = false
  and if exists(top.getLocation()) then hasLocation = true else hasLocation = false
  and hasToString = false
select top.getAPrimaryQlClass(), hasToString, hasLocation

Query Console link

JavaScript (not affected?)

import javascript

from Locatable l, boolean hasToString, boolean hasLocation
where
  if exists(l.toString()) then hasToString = true else hasToString = false
  and if exists(l.getLocation()) then hasLocation = true else hasLocation = false
  and hasToString = false
select l.getAPrimaryQlClass(), hasToString, hasLocation

Query Console link

Python (not affected?)

import python

from AstNode n, boolean hasToString, boolean hasLocation
where
  if exists(n.toString()) then hasToString = true else hasToString = false
  and if exists(n.getLocation()) then hasLocation = true else hasLocation = false
  and hasToString = false
select hasToString, hasLocation

Query Console link

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions