github / github/codeql

[question?] counterintuitive class method behaviour

Aperta
#21,670 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub
question
Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 15h
PR unite (30g)
141

Descrizione

When I write a query like this:
```codeql
class Meow extends Struct {
Field f;
Meow() {
f.getDeclaringType() = this
}
Field getField() { result = f }
}

from Meow m
select m, m.getField(), m.getField()
```
My mental model of this is: "`Meow` is essentially a (struct, struct's field) tuple. `from Meow m` will select all of those tuples. For each of those , `select m, m.getField(), m.getField()` will print their contents."

But that is actually not what happens, because you get results like this:
```
| m | col1 | col2 |
+-----------------------------------+-----------------------------------------------------+-----------------------------------------------------+
// [snip]
| port_io_ops | f_inb | f_outb |
// [snip]
```
Which means that the first `m.getField()` and the second `m.getField()` are operating on different `Meow` objects.

I've been debugging a bug in my query for hours now only to realize that this is what happens. Is this really intended? I read through a non-trivial amount of documentation and did not realize this, I feel like my whole mental model of how codeql works is shattering :S

(If it is really intended, could the documentation be updated to point this out more clearly?)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start with the CodeQL query and output shown in the issue, then read the documentation covering class methods and predicate evaluation. Confirm the intended behavior and identify the relevant documentation section; done means the behavior is explained clearly enough to address the reported mental-model gap.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.