github / github/codeql

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

未關閉
#5,290 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

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)
```ql
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](https://lgtm.com/query/7279762177209777278/)

# C# (affected)
```ql
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](https://lgtm.com/query/4316710491514805982/)

# Go
Not sure if affected; there are no demo projects to scan.
```ql
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
```ql
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](https://lgtm.com/query/2811528914731288766/)

# JavaScript (not affected?)
```ql
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](https://lgtm.com/query/1772034542434545159/)

# Python (not affected?)
```ql
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](https://lgtm.com/query/6347168432907377414/)

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。