Skip to content

Commit 8341f88

Browse files
committed
Ruby printAst: fix order for synth children of real parents
Real parents can have synthesized children, so always assigning index 0 leads to nondeterminism in graph output.
1 parent 40f80ff commit 8341f88

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

ruby/ql/lib/codeql/ruby/printAst.qll

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ class PrintRegularAstNode extends PrintAstNode, TPrintRegularAstNode {
121121
}
122122

123123
private int getSynthAstNodeIndex() {
124-
this.parentIsSynthesized() and
125-
exists(AstNode parent |
124+
if exists(AstNode parent |
125+
shouldPrintAstEdge(parent, _, astNode) and
126+
synthChild(parent, _, astNode)
127+
)
128+
then exists(AstNode parent |
126129
shouldPrintAstEdge(parent, _, astNode) and
127-
parent.isSynthesized() and
128130
synthChild(parent, result, astNode)
129131
)
130-
or
131-
not this.parentIsSynthesized() and
132-
result = 0
132+
else result = 0
133133
}
134134

135135
override int getOrder() {

ruby/ql/test/library-tests/ast/Ast.expected

+8-8
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ control/cases.rb:
915915
# 56| getValue: [IntegerLiteral] 5
916916
# 56| getKey: [SymbolLiteral] :b
917917
# 56| getComponent: [StringTextComponent] b
918-
# 56| getValue: [LocalVariableAccess] b
919918
# 56| getRestVariableAccess: [LocalVariableAccess] map
919+
# 56| getValue: [LocalVariableAccess] b
920920
# 57| getBranch: [InClause] in ... then ...
921921
# 57| getPattern: [HashPattern] { ..., ** }
922922
# 57| getKey: [SymbolLiteral] :a
@@ -1006,8 +1006,8 @@ control/cases.rb:
10061006
# 75| getValue: [IntegerLiteral] 5
10071007
# 75| getKey: [SymbolLiteral] :b
10081008
# 75| getComponent: [StringTextComponent] b
1009-
# 75| getValue: [LocalVariableAccess] b
10101009
# 75| getRestVariableAccess: [LocalVariableAccess] map
1010+
# 75| getValue: [LocalVariableAccess] b
10111011
# 76| getBranch: [InClause] in ... then ...
10121012
# 76| getPattern: [HashPattern] { ..., ** }
10131013
# 76| getKey: [SymbolLiteral] :a
@@ -1209,8 +1209,8 @@ control/cases.rb:
12091209
# 141| getValue: [IntegerLiteral] 1
12101210
# 141| getKey: [SymbolLiteral] :a
12111211
# 141| getComponent: [StringTextComponent] a
1212-
# 141| getValue: [LocalVariableAccess] a
12131212
# 141| getRestVariableAccess: [LocalVariableAccess] rest
1213+
# 141| getValue: [LocalVariableAccess] a
12141214
# 142| getBranch: [InClause] in ... then ...
12151215
# 142| getPattern: [HashPattern] { ..., ** }
12161216
# 142| getClass: [ConstantReadAccess] Foo
@@ -3185,14 +3185,14 @@ params/params.rb:
31853185
# 106| getParameter: [HashSplatParameter] **kwargs
31863186
# 106| getDefiningAccess: [LocalVariableAccess] kwargs
31873187
# 107| getStmt: [SuperCall] super call to m
3188-
# 107| getArgument: [HashSplatExpr] ** ...
3189-
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] kwargs
3188+
# 107| getArgument: [LocalVariableAccess] y
3189+
# 107| getArgument: [SplatExpr] * ...
3190+
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] rest
31903191
# 107| getArgument: [Pair] Pair
31913192
# 107| getKey: [SymbolLiteral] k
31923193
# 107| getValue: [LocalVariableAccess] k
3193-
# 107| getArgument: [SplatExpr] * ...
3194-
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] rest
3195-
# 107| getArgument: [LocalVariableAccess] y
3194+
# 107| getArgument: [HashSplatExpr] ** ...
3195+
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] kwargs
31963196
# 111| getStmt: [MethodCall] call to m
31973197
# 111| getReceiver: [MethodCall] call to new
31983198
# 111| getReceiver: [ConstantReadAccess] Sub

0 commit comments

Comments
 (0)