Skip to content

Commit 9ccd8cd

Browse files
committed
Ruby: Update documentation
1 parent ef63ea8 commit 9ccd8cd

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,46 +1025,43 @@ private module ParameterNodes {
10251025
* For example, in the following code:
10261026
*
10271027
* ```rb
1028-
* def foo(x, y); end
1028+
* def foo(x, y, z); end
10291029
*
1030-
* foo(*[a, b])
1030+
* foo(a, *[b, c])
10311031
* ```
10321032
*
1033-
* We want `a` to flow to `x` and `b` to flow to `y`. We do this by constructing
1033+
* We want `b` to flow to `y` and `c` to flow to `z`. We do this by constructing
10341034
* a `SynthSplatParameterNode` for the method `foo`, and matching the splat argument to this
10351035
* parameter node via `parameterMatch/2`. We then add read steps from this node to parameters
1036-
* `x` and `y`, for content at indices 0 and 1 respectively (see `readStep`).
1036+
* `y` and `z`, for content at indices 0 and 1 respectively (see `readStep`).
10371037
*
1038-
* We don't yet correctly handle cases where the splat argument is not the first argument, e.g. in
1039-
* ```rb
1040-
* foo(a, *[b])
1041-
* ```
1042-
*
1043-
* TODO: we do now support the above, but we don't support this case:
1038+
* This node stores the index of the splat argument it is matched to, which allows us to shift
1039+
* indices correctly when adding read steps. Without this, in the example above we would erroneously
1040+
* get a read step to `x` and index 0 and `y` and index 1 etc.
10441041
*
1042+
* We don't yet correctly handle cases where a positional argument follows the splat argument, e.g. in
10451043
* ```rb
10461044
* foo(a, *[b], c)
10471045
* ```
1048-
*
1049-
* Update this documentation.
10501046
*/
10511047
class SynthSplatParameterNode extends ParameterNodeImpl, TSynthSplatParameterNode {
10521048
private DataFlowCallable callable;
1049+
// The position of the splat argument that is matched to this node
10531050
private int n;
10541051

10551052
SynthSplatParameterNode() { this = TSynthSplatParameterNode(callable, n) }
10561053

10571054
/**
1058-
* Gets a parameter which will contain the value given by `c`, assuming
1059-
* that the method was called with a single splat argument.
1060-
* For example, if the synth splat parameter is for the following method
1055+
* Gets a parameter which will contain the value given by `c`.
1056+
* For example, if the synth splat parameter is for the following method and method call:
10611057
*
10621058
* ```rb
1063-
* def foo(x, y, a:, *rest)
1064-
* end
1059+
* def foo(x, y, a:, *rest); end
1060+
*
1061+
* foo(arg1, *args)
10651062
* ```
10661063
*
1067-
* then `getAParameter(element 0) = x` and `getAParameter(element 1) = y`.
1064+
* then `getAParameter(element 0) = y`.
10681065
*/
10691066
ParameterNode getAParameter(ContentSet c) {
10701067
exists(int m |

0 commit comments

Comments
 (0)