Ruby: Three call graph fixes for singleton methods

This commit is contained in:
Tom Hvitved
2022-09-19 11:57:40 +02:00
parent d13332cff1
commit bb08e6f0fd
2 changed files with 10 additions and 7 deletions

View File

@@ -354,7 +354,7 @@ private module Cached {
// end
// end
// ```
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), _, m)
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), _, m.getSuperClass*())
)
)
or
@@ -509,16 +509,17 @@ private DataFlow::Node trackInstance(Module tp, boolean exact, TypeTracker t) {
// `self.new` inside a module
selfInModule(sourceNode.(SsaSelfDefinitionNode).getVariable(), tp)
or
// `self.new` inside a (singleton) method
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), _, tp)
// `self.new` inside a singleton method
selfInMethod(sourceNode.(SsaSelfDefinitionNode).getVariable(), any(SingletonMethod sm), tp)
)
or
// `self` reference in method or top-level (but not in module, where instance
// methods cannot be called; only singleton methods)
// `self` reference in method or top-level (but not in module or singleton method,
// where instance methods cannot be called; only singleton methods)
result =
any(SsaSelfDefinitionNode self |
exists(MethodBase m |
selfInMethod(self.getVariable(), m, tp) and
not m instanceof SingletonMethod and
if m.getEnclosingModule() instanceof Toplevel then exact = true else exact = false
)
or

View File

@@ -9,7 +9,6 @@ getTarget
| calls.rb:19:1:19:8 | call to foo | calls.rb:1:1:3:3 | foo |
| calls.rb:19:1:19:8 | call to foo | calls.rb:85:1:89:3 | foo |
| calls.rb:23:9:23:19 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
| calls.rb:26:9:26:18 | call to instance_m | calls.rb:22:5:24:7 | instance_m |
| calls.rb:32:5:32:15 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
| calls.rb:33:5:33:20 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
| calls.rb:37:1:37:13 | call to singleton_m | calls.rb:25:5:27:7 | singleton_m |
@@ -114,7 +113,6 @@ getTarget
| calls.rb:305:1:305:22 | call to singleton_j | calls.rb:300:5:302:7 | singleton_j |
| calls.rb:309:9:309:31 | call to puts | calls.rb:102:5:102:30 | puts |
| calls.rb:310:9:310:11 | call to new | calls.rb:114:5:114:16 | new |
| calls.rb:310:9:310:20 | call to instance | calls.rb:308:5:311:7 | instance |
| calls.rb:314:9:314:11 | call to new | calls.rb:114:5:114:16 | new |
| calls.rb:314:9:314:20 | call to instance | calls.rb:308:5:311:7 | instance |
| calls.rb:317:5:317:7 | call to new | calls.rb:114:5:114:16 | new |
@@ -150,8 +148,10 @@ getTarget
| calls.rb:372:1:372:11 | call to instance | calls.rb:365:5:367:7 | instance |
| calls.rb:377:13:377:48 | call to puts | calls.rb:102:5:102:30 | puts |
| calls.rb:381:13:381:22 | call to singleton1 | calls.rb:376:9:378:11 | singleton1 |
| calls.rb:381:13:381:22 | call to singleton1 | calls.rb:401:9:403:11 | singleton1 |
| calls.rb:386:9:386:44 | call to puts | calls.rb:102:5:102:30 | puts |
| calls.rb:390:9:390:18 | call to singleton2 | calls.rb:385:5:387:7 | singleton2 |
| calls.rb:390:9:390:18 | call to singleton2 | calls.rb:406:5:408:7 | singleton2 |
| calls.rb:393:5:393:14 | call to singleton2 | calls.rb:385:5:387:7 | singleton2 |
| calls.rb:396:1:396:34 | call to call_singleton1 | calls.rb:380:9:382:11 | call_singleton1 |
| calls.rb:397:1:397:34 | call to call_singleton2 | calls.rb:389:5:391:7 | call_singleton2 |
@@ -187,6 +187,7 @@ getTarget
| private.rb:51:3:51:19 | call to private | calls.rb:109:5:109:20 | private |
| private.rb:53:3:53:9 | call to private | calls.rb:109:5:109:20 | private |
unresolvedCall
| calls.rb:26:9:26:18 | call to instance_m |
| calls.rb:29:5:29:14 | call to instance_m |
| calls.rb:30:5:30:19 | call to instance_m |
| calls.rb:36:1:36:12 | call to instance_m |
@@ -216,6 +217,7 @@ unresolvedCall
| calls.rb:258:1:258:14 | call to singleton_g |
| calls.rb:271:1:271:14 | call to singleton_g |
| calls.rb:273:1:273:14 | call to singleton_g |
| calls.rb:310:9:310:20 | call to instance |
| calls.rb:411:1:411:34 | call to call_singleton1 |
| calls.rb:412:1:412:34 | call to call_singleton2 |
| hello.rb:20:16:20:26 | ... + ... |