Address review comments

This commit is contained in:
Tom Hvitved
2022-05-19 15:32:24 +02:00
parent faf24a4f18
commit 63c70b9e7a
2 changed files with 25 additions and 4 deletions

View File

@@ -71,8 +71,8 @@ module SummaryComponent {
}
/** Gets a summary component that represents a value in a pair at a known key. */
SummaryComponent pairValueKnown(ConstantValue cv) {
result = SC::content(TSingletonContent(TKnownPairValueContent(cv)))
SummaryComponent pairValueKnown(ConstantValue key) {
result = SC::content(TSingletonContent(TKnownPairValueContent(key)))
}
/** Gets a summary component that represents the return value of a call. */

View File

@@ -65,6 +65,20 @@ module Hash {
}
}
/**
* `Hash[]` called on an existing hash, e.g.
*
* ```rb
* h = {foo: 0, bar: 1, baz: 2}
* Hash[h] # => {:foo=>0, :bar=>1, :baz=>2}
* ```
*
* or on a 2-element array, e.g.
*
* ```rb
* Hash[ [ [:foo, 0], [:bar, 1] ] ] # => {:foo=>0, :bar=>1}
* ```
*/
private class HashNewSummary extends SummarizedCallable {
HashNewSummary() { this = "Hash[]" }
@@ -87,11 +101,18 @@ module Hash {
}
}
private class HashNewSummary2 extends SummarizedCallable {
/**
* `Hash[]` called on an even number of arguments, e.g.
*
* ```rb
* Hash[:foo, 0, :bar, 1] # => {:foo=>0, :bar=>1}
* ```
*/
private class HashNewSuccessivePairsSummary extends SummarizedCallable {
private int i;
private ConstantValue cv;
HashNewSummary2() {
HashNewSuccessivePairsSummary() {
this = "Hash[" + i + ", " + cv.serialize() + "]" and
i % 2 = 1 and
exists(ElementReference er |