Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Ruby printAst: fix order for synth children of real parents #19448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: fix
---
### Bug Fixes

* The Ruby printAst.qll library now orders AST nodes slightly differently: child nodes that do not literally appear in the source code, but whose parent nodes do, are assigned a deterministic order based on a combination of source location and logical order within the parent. This fixes the non-deterministic ordering that sometimes occurred depending on evaluation order. The effect may also be visible in downstream uses of the printAst library, such as the AST view in the VSCode extension.
16 changes: 11 additions & 5 deletions 16 ruby/ql/lib/codeql/ruby/printAst.qll
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,22 @@ class PrintRegularAstNode extends PrintAstNode, TPrintRegularAstNode {
}

private int getSynthAstNodeIndex() {
this.parentIsSynthesized() and
exists(AstNode parent |
shouldPrintAstEdge(parent, _, astNode) and
parent.isSynthesized() and
synthChild(parent, result, astNode)
)
or
not this.parentIsSynthesized() and
not exists(AstNode parent |
shouldPrintAstEdge(parent, _, astNode) and
synthChild(parent, _, astNode)
) and
result = 0
}

private int getSynthAstNodeIndexForSynthParent() {
if this.parentIsSynthesized() then result = this.getSynthAstNodeIndex() else result = 0
}

override int getOrder() {
this =
rank[result](PrintRegularAstNode p, Location l, File f |
Expand All @@ -140,8 +145,9 @@ class PrintRegularAstNode extends PrintAstNode, TPrintRegularAstNode {
|
p
order by
f.getBaseName(), f.getAbsolutePath(), l.getStartLine(), p.getSynthAstNodeIndex(),
l.getStartColumn(), l.getEndLine(), l.getEndColumn()
f.getBaseName(), f.getAbsolutePath(), l.getStartLine(),
p.getSynthAstNodeIndexForSynthParent(), l.getStartColumn(), p.getSynthAstNodeIndex(),
l.getEndLine(), l.getEndColumn()
)
}

Expand Down
10 changes: 5 additions & 5 deletions 10 ruby/ql/test/library-tests/ast/Ast.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3185,14 +3185,14 @@ params/params.rb:
# 106| getParameter: [HashSplatParameter] **kwargs
# 106| getDefiningAccess: [LocalVariableAccess] kwargs
# 107| getStmt: [SuperCall] super call to m
# 107| getArgument: [HashSplatExpr] ** ...
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] kwargs
# 107| getArgument: [LocalVariableAccess] y
# 107| getArgument: [SplatExpr] * ...
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] rest
# 107| getArgument: [Pair] Pair
# 107| getKey: [SymbolLiteral] k
# 107| getValue: [LocalVariableAccess] k
# 107| getArgument: [SplatExpr] * ...
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] rest
# 107| getArgument: [LocalVariableAccess] y
# 107| getArgument: [HashSplatExpr] ** ...
# 107| getAnOperand/getOperand/getReceiver: [LocalVariableAccess] kwargs
# 111| getStmt: [MethodCall] call to m
# 111| getReceiver: [MethodCall] call to new
# 111| getReceiver: [ConstantReadAccess] Sub
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.