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: Add type row for extends calls #15311

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from
Draft
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
Expand Up @@ -335,7 +335,7 @@ DataFlowCallable viableLibraryCallable(DataFlowCall call) {

/** Holds if there is a call like `receiver.extend(M)`. */
pragma[nomagic]
private predicate extendCall(DataFlow::ExprNode receiver, Module m) {
predicate extendCall(DataFlow::ExprNode receiver, Module m) {
exists(DataFlow::CallNode extendCall |
extendCall.getMethodName() = "extend" and
exists(DataFlow::LocalSourceNode sourceNode | sourceNode.flowsTo(extendCall.getArgument(_)) |
Expand Down
17 changes: 17 additions & 0 deletions 17 ruby/ql/src/queries/modeling/internal/Types.qll
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ private import codeql.ruby.ApiGraphs
private import Util as Util
private import codeql.ruby.ast.Module
private import codeql.ruby.ast.internal.Module
private import codeql.ruby.dataflow.internal.DataFlowDispatch
private import codeql.ruby.dataflow.internal.DataFlowPrivate

/**
* Contains predicates for generating `typeModel`s that contain typing
Expand Down Expand Up @@ -52,5 +54,20 @@ module Types {
|
m1.getQualifiedName() = type1 and m2.getQualifiedName() = type2 and path = ""
)
or
// module Type1
// class Type2
// extend Type1
exists(Module m1, Module m2, DataFlow::ExprNode receiver |
extendCall(receiver, m1) and
exists(SsaSelfDefinitionNode self |
self.getVariable() = m2.getADeclaration().getModuleSelfVariable() and
self.(DataFlow::LocalSourceNode).flowsTo(receiver)
)
|
m1.getQualifiedName() = type1 and
m2.getQualifiedName() + "!" = type2 and
path = ""
)
}
}
5 changes: 4 additions & 1 deletion 5 ruby/ql/src/queries/modeling/internal/Util.qll
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ private import codeql.ruby.ApiGraphs
* In practice, this means a file that is not part of test code.
*/
class RelevantFile extends File {
RelevantFile() { not this.getRelativePath().regexpMatch(".*/?test(case)?s?/.*") }
RelevantFile() {
not this.getRelativePath().regexpMatch(".*/?test(case)?s?/.*") or
this.getAbsolutePath().matches("%/ql/test/%") // allows our test cases to work
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ sinkModel
typeVariableModel
typeModel
| M1 | B | |
| M1 | C! | |
summaryModel
Morty Proxy This is a proxified and sanitized view of the page, visit original site.