Skip to content

Commit b5bef24

Browse files
authored
QL: Add test for override
This test demonstrates that our handling of `override` is incorrect. Quick-eval'ing the `test` predicate produces the following output: | f | i | j | +---+-----+-----+ | 1 | 10 | 10 | | 1 | 10 | 100 | | 1 | 100 | 10 | | 1 | 100 | 100 | | 2 | 20 | 20 | | 3 | 3 | 3 | this demonstrates that `f.bar` and `f.baz` can resolve to all predicates of that name in the file. However, at present we only capture the calls to members on `Foo`.
1 parent fb491c3 commit b5bef24

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

ql/test/callgraph/Overrides.qll

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import ql
2+
3+
class Foo extends int {
4+
Foo() { this in [1, 2, 3] }
5+
6+
int bar() { result = this }
7+
8+
predicate baz(int i) { i = this.bar() }
9+
}
10+
11+
class Bar extends Foo {
12+
Bar() { this = [1, 2] }
13+
14+
override int bar() { result = 10 * this }
15+
16+
override predicate baz(int i) { i = this.bar() }
17+
}
18+
19+
class Baz extends Foo {
20+
Baz() { this = 1 }
21+
22+
override int bar() { result = 100 * this }
23+
24+
override predicate baz(int i) { i = this.bar() }
25+
}
26+
27+
query predicate test(Foo f, int i, int j) {
28+
f.bar() = i and
29+
f.baz(j)
30+
}

ql/test/callgraph/callgraph.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@
66
| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:26:3:26:32 | ClasslessPredicate alias2 |
77
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:22:3:22:32 | ClasslessPredicate myThing0 |
88
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:24:3:24:32 | ClasslessPredicate alias0 |
9+
| Overrides.qll:8:30:8:39 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
10+
| Overrides.qll:16:39:16:48 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
11+
| Overrides.qll:16:39:16:48 | MemberCall | Overrides.qll:14:12:14:43 | ClassPredicate bar |
12+
| Overrides.qll:24:39:24:48 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
13+
| Overrides.qll:24:39:24:48 | MemberCall | Overrides.qll:22:12:22:44 | ClassPredicate bar |
14+
| Overrides.qll:28:3:28:9 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
15+
| Overrides.qll:29:3:29:10 | MemberCall | Overrides.qll:8:3:8:41 | ClassPredicate baz |

0 commit comments

Comments
 (0)