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`.
This commit is contained in:
Taus
2021-10-14 08:50:51 +00:00
committed by GitHub
parent f7ff83c2e7
commit 5a519c5089
2 changed files with 37 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import ql
class Foo extends int {
Foo() { this in [1, 2, 3] }
int bar() { result = this }
predicate baz(int i) { i = this.bar() }
}
class Bar extends Foo {
Bar() { this = [1, 2] }
override int bar() { result = 10 * this }
override predicate baz(int i) { i = this.bar() }
}
class Baz extends Foo {
Baz() { this = 1 }
override int bar() { result = 100 * this }
override predicate baz(int i) { i = this.bar() }
}
query predicate test(Foo f, int i, int j) {
f.bar() = i and
f.baz(j)
}

View File

@@ -6,3 +6,10 @@
| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:26:3:26:32 | ClasslessPredicate alias2 |
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:22:3:22:32 | ClasslessPredicate myThing0 |
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:24:3:24:32 | ClasslessPredicate alias0 |
| Overrides.qll:8:30:8:39 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
| Overrides.qll:16:39:16:48 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
| Overrides.qll:16:39:16:48 | MemberCall | Overrides.qll:14:12:14:43 | ClassPredicate bar |
| Overrides.qll:24:39:24:48 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
| Overrides.qll:24:39:24:48 | MemberCall | Overrides.qll:22:12:22:44 | ClassPredicate bar |
| Overrides.qll:28:3:28:9 | MemberCall | Overrides.qll:6:3:6:29 | ClassPredicate bar |
| Overrides.qll:29:3:29:10 | MemberCall | Overrides.qll:8:3:8:41 | ClassPredicate baz |