Merge pull request #7446 from jeffgran/jg/constant-write-access

[Ruby] Bugfix: ConstantWriteAccess::getQualifiedName() returns wrong value in some cases
This commit is contained in:
Alex Ford
2021-12-22 17:07:49 +00:00
committed by GitHub
9 changed files with 228 additions and 51 deletions

View File

@@ -0,0 +1,2 @@
lgtm,codescanning
* `ConstantWriteAccess.getQualifiedName()` has been deprecated in favor of `getAQualifiedName()` which can return multiple possible qualified names for a given constant write access.

View File

@@ -168,7 +168,7 @@ class ConstantWriteAccess extends ConstantAccess {
override string getAPrimaryQlClass() { result = "ConstantWriteAccess" }
/**
* Gets the fully qualified name for this constant, based on the context in
* Gets a fully qualified name for this constant, based on the context in
* which it is defined.
*
* For example, given
@@ -184,17 +184,31 @@ class ConstantWriteAccess extends ConstantAccess {
*
* the constant `Baz` has the fully qualified name `Foo::Bar::Baz`, and
* `CONST_A` has the fully qualified name `Foo::CONST_A`.
*
* Important note: This can return more than one value, because there are
* situations where there can be multiple possible "fully qualified" names.
* For example:
* ```
* module Mod4
* include Mod1
* module Mod3::Mod5 end
* end
* ```
* In the above snippet, `Mod5` has two valid fully qualified names it can be
* referred to by: `Mod1::Mod3::Mod5`, or `Mod4::Mod3::Mod5`.
*
* Another example has to do with the order in which module definitions are
* executed at runtime. Because of the way that ruby dynamically looks up
* constants up the namespace chain, the fully qualified name of a nested
* constant can be ambiguous from just statically looking at the AST.
*/
string getQualifiedName() {
/* get the qualified name for the parent module, then append w */
exists(ConstantWriteAccess parent | parent = this.getEnclosingModule() |
result = parent.getQualifiedName() + "::" + this.getName()
)
or
/* base case - there's no parent module */
not exists(ConstantWriteAccess parent | parent = this.getEnclosingModule()) and
result = this.getName()
}
string getAQualifiedName() { result = resolveConstantWriteAccess(this) }
/**
* Gets a qualified name for this constant. Deprecated in favor of
* `getAQualifiedName` because this can return more than one value
*/
deprecated string getQualifiedName() { result = this.getAQualifiedName() }
}
/**

View File

@@ -278,7 +278,7 @@ private class ActiveRecordModelFinderCall extends ActiveRecordModelInstantiation
ActiveRecordModelFinderCall() {
call = this.asExpr().getExpr() and
recv = getUltimateReceiver(call) and
resolveConstant(recv) = cls.getQualifiedName() and
resolveConstant(recv) = cls.getAQualifiedName() and
call.getMethodName() = finderMethodName()
}

View File

@@ -78,7 +78,7 @@ ConstantWriteAccess definitionOf(string fqn) {
fqn = resolveConstant(_) and
result =
min(ConstantWriteAccess w, Location l |
w.getQualifiedName() = fqn and l = w.getLocation()
w.getAQualifiedName() = fqn and l = w.getLocation()
|
w
order by

View File

@@ -1333,24 +1333,76 @@ constants/constants.rb:
# 31| getScopeExpr: [ConstantReadAccess] ModuleA
# 31| getSuperclassExpr: [ConstantReadAccess] ClassA
# 31| getScopeExpr: [ConstantReadAccess] ModuleA
# 34| getStmt: [ModuleDeclaration] ModuleC
# 34| getScopeExpr: [ConstantReadAccess] ModuleA
# 37| getStmt: [AssignExpr] ... = ...
# 37| getAnOperand/getLeftOperand: [ConstantAssignment] MAX_SIZE
# 37| getScopeExpr: [ConstantReadAccess] ModuleB
# 37| getScopeExpr: [ConstantReadAccess] ModuleA
# 37| getAnOperand/getRightOperand: [IntegerLiteral] 1024
# 39| getStmt: [MethodCall] call to puts
# 39| getReceiver: [Self, SelfVariableAccess] self
# 39| getArgument: [ConstantReadAccess] MAX_SIZE
# 32| getStmt: [AssignExpr] ... = ...
# 32| getAnOperand/getLeftOperand: [ConstantAssignment] FOURTY_TWO
# 32| getAnOperand/getRightOperand: [IntegerLiteral] 42
# 35| getStmt: [ModuleDeclaration] ModuleC
# 35| getScopeExpr: [ConstantReadAccess] ModuleA
# 36| getStmt: [AssignExpr] ... = ...
# 36| getAnOperand/getLeftOperand: [ConstantAssignment] FOURTY_THREE
# 36| getAnOperand/getRightOperand: [IntegerLiteral] 43
# 39| getStmt: [AssignExpr] ... = ...
# 39| getAnOperand/getLeftOperand: [ConstantAssignment] MAX_SIZE
# 39| getScopeExpr: [ConstantReadAccess] ModuleB
# 39| getScopeExpr: [ConstantReadAccess] ModuleA
# 39| getAnOperand/getRightOperand: [IntegerLiteral] 1024
# 41| getStmt: [MethodCall] call to puts
# 41| getReceiver: [Self, SelfVariableAccess] self
# 41| getArgument: [ConstantReadAccess] GREETING
# 42| getStmt: [MethodCall] call to puts
# 42| getReceiver: [Self, SelfVariableAccess] self
# 42| getArgument: [ConstantReadAccess] GREETING
# 41| getArgument: [ConstantReadAccess] MAX_SIZE
# 41| getScopeExpr: [ConstantReadAccess] ModuleB
# 41| getScopeExpr: [ConstantReadAccess] ModuleA
# 43| getStmt: [MethodCall] call to puts
# 43| getReceiver: [Self, SelfVariableAccess] self
# 43| getArgument: [ConstantReadAccess] GREETING
# 44| getStmt: [MethodCall] call to puts
# 44| getReceiver: [Self, SelfVariableAccess] self
# 44| getArgument: [ConstantReadAccess] GREETING
# 46| getStmt: [ModuleDeclaration] ModuleB
# 46| getScopeExpr: [ConstantReadAccess] ModuleA
# 47| getStmt: [ClassDeclaration] ClassB
# 47| getSuperclassExpr: [ConstantReadAccess] Base
# 48| getStmt: [AssignExpr] ... = ...
# 48| getAnOperand/getLeftOperand: [ConstantAssignment] FOURTY_ONE
# 48| getAnOperand/getRightOperand: [IntegerLiteral] 41
# 52| getStmt: [ModuleDeclaration] ModuleA
# 53| getStmt: [AssignExpr] ... = ...
# 53| getAnOperand/getLeftOperand: [ConstantAssignment] FOURTY_FOUR
# 53| getAnOperand/getRightOperand: [StringLiteral] "fourty-four"
# 53| getComponent: [StringTextComponent] fourty-four
# 54| getStmt: [ClassDeclaration] ClassB
# 54| getScopeExpr: [ConstantReadAccess] ModuleB
# 54| getSuperclassExpr: [ConstantReadAccess] Base
# 55| getStmt: [AssignExpr] ... = ...
# 55| getAnOperand/getLeftOperand: [ClassVariableAccess] @@fourty_four
# 55| getAnOperand/getRightOperand: [ConstantReadAccess] FOURTY_FOUR
# 56| getStmt: [AssignExpr] ... = ...
# 56| getAnOperand/getLeftOperand: [ConstantAssignment] FOURTY_FOUR
# 56| getAnOperand/getRightOperand: [IntegerLiteral] 44
# 57| getStmt: [AssignExpr] ... = ...
# 57| getAnOperand/getLeftOperand: [ClassVariableAccess] @@fourty_four
# 57| getAnOperand/getRightOperand: [ConstantReadAccess] FOURTY_FOUR
# 61| getStmt: [ModuleDeclaration] Mod1
# 62| getStmt: [ModuleDeclaration] Mod3
# 63| getStmt: [AssignExpr] ... = ...
# 63| getAnOperand/getLeftOperand: [ConstantAssignment] FOURTY_FIVE
# 63| getAnOperand/getRightOperand: [IntegerLiteral] 45
# 65| getStmt: [AssignExpr] ... = ...
# 65| getAnOperand/getLeftOperand: [ClassVariableAccess] @@fourty_five
# 65| getAnOperand/getRightOperand: [ConstantReadAccess] FOURTY_FIVE
# 65| getScopeExpr: [ConstantReadAccess] Mod3
# 68| getStmt: [ModuleDeclaration] Mod4
# 69| getStmt: [MethodCall] call to include
# 69| getReceiver: [Self, SelfVariableAccess] self
# 69| getArgument: [ConstantReadAccess] Mod1
# 70| getStmt: [ModuleDeclaration] Mod5
# 70| getScopeExpr: [ConstantReadAccess] Mod3
# 71| getStmt: [AssignExpr] ... = ...
# 71| getAnOperand/getLeftOperand: [ConstantAssignment] FOURTY_SIX
# 71| getAnOperand/getRightOperand: [IntegerLiteral] 46
# 73| getStmt: [AssignExpr] ... = ...
# 73| getAnOperand/getLeftOperand: [ClassVariableAccess] @@fourty_six
# 73| getAnOperand/getRightOperand: [ConstantReadAccess] FOURTY_SIX
# 73| getScopeExpr: [ConstantReadAccess] Mod3
literals/literals.rb:
# 1| [Toplevel] literals.rb
# 2| getStmt: [NilLiteral] nil

View File

@@ -74,8 +74,20 @@
| constants/constants.rb:20:22:20:28 | "Chuck" | Chuck |
| constants/constants.rb:20:31:20:36 | "Dave" | Dave |
| constants/constants.rb:28:11:28:15 | "foo" | foo |
| constants/constants.rb:37:30:37:33 | 1024 | 1024 |
| constants/constants.rb:39:6:39:31 | MAX_SIZE | 1024 |
| constants/constants.rb:32:16:32:17 | 42 | 42 |
| constants/constants.rb:36:18:36:19 | 43 | 43 |
| constants/constants.rb:39:30:39:33 | 1024 | 1024 |
| constants/constants.rb:41:6:41:31 | MAX_SIZE | 1024 |
| constants/constants.rb:48:18:48:19 | 41 | 41 |
| constants/constants.rb:53:17:53:29 | "fourty-four" | fourty-four |
| constants/constants.rb:55:21:55:31 | FOURTY_FOUR | 44 |
| constants/constants.rb:55:21:55:31 | FOURTY_FOUR | fourty-four |
| constants/constants.rb:56:19:56:20 | 44 | 44 |
| constants/constants.rb:57:21:57:31 | FOURTY_FOUR | 44 |
| constants/constants.rb:57:21:57:31 | FOURTY_FOUR | fourty-four |
| constants/constants.rb:63:19:63:20 | 45 | 45 |
| constants/constants.rb:65:19:65:35 | FOURTY_FIVE | 45 |
| constants/constants.rb:71:18:71:19 | 46 | 46 |
| control/cases.rb:2:5:2:5 | 0 | 0 |
| control/cases.rb:3:5:3:5 | 0 | 0 |
| control/cases.rb:4:5:4:5 | 0 | 0 |

View File

@@ -20,41 +20,87 @@ constantAccess
| constants.rb:20:13:20:37 | Array | read | Array | ConstantReadAccess |
| constants.rb:22:5:22:9 | Names | read | Names | ConstantReadAccess |
| constants.rb:23:18:23:25 | GREETING | read | GREETING | ConstantReadAccess |
| constants.rb:31:1:32:3 | ClassD | write | ClassD | ClassDeclaration |
| constants.rb:31:1:33:3 | ClassD | write | ClassD | ClassDeclaration |
| constants.rb:31:7:31:13 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:31:25:31:31 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:31:25:31:39 | ClassA | read | ClassA | ConstantReadAccess |
| constants.rb:34:1:35:3 | ModuleC | write | ModuleC | ModuleDeclaration |
| constants.rb:34:8:34:14 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:37:1:37:7 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:37:1:37:16 | ModuleB | read | ModuleB | ConstantReadAccess |
| constants.rb:37:1:37:26 | MAX_SIZE | write | MAX_SIZE | ConstantAssignment |
| constants.rb:39:6:39:12 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:39:6:39:21 | ModuleB | read | ModuleB | ConstantReadAccess |
| constants.rb:39:6:39:31 | MAX_SIZE | read | MAX_SIZE | ConstantReadAccess |
| constants.rb:41:6:41:13 | GREETING | read | GREETING | ConstantReadAccess |
| constants.rb:42:6:42:15 | GREETING | read | GREETING | ConstantReadAccess |
| constants.rb:32:3:32:12 | FOURTY_TWO | write | FOURTY_TWO | ConstantAssignment |
| constants.rb:35:1:37:3 | ModuleC | write | ModuleC | ModuleDeclaration |
| constants.rb:35:8:35:14 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:36:3:36:14 | FOURTY_THREE | write | FOURTY_THREE | ConstantAssignment |
| constants.rb:39:1:39:7 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:39:1:39:16 | ModuleB | read | ModuleB | ConstantReadAccess |
| constants.rb:39:1:39:26 | MAX_SIZE | write | MAX_SIZE | ConstantAssignment |
| constants.rb:41:6:41:12 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:41:6:41:21 | ModuleB | read | ModuleB | ConstantReadAccess |
| constants.rb:41:6:41:31 | MAX_SIZE | read | MAX_SIZE | ConstantReadAccess |
| constants.rb:43:6:43:13 | GREETING | read | GREETING | ConstantReadAccess |
| constants.rb:44:6:44:15 | GREETING | read | GREETING | ConstantReadAccess |
| constants.rb:46:1:50:3 | ModuleB | write | ModuleB | ModuleDeclaration |
| constants.rb:46:8:46:14 | ModuleA | read | ModuleA | ConstantReadAccess |
| constants.rb:47:3:49:5 | ClassB | write | ClassB | ClassDeclaration |
| constants.rb:47:18:47:21 | Base | read | Base | ConstantReadAccess |
| constants.rb:48:5:48:14 | FOURTY_ONE | write | FOURTY_ONE | ConstantAssignment |
| constants.rb:52:1:59:3 | ModuleA | write | ModuleA | ModuleDeclaration |
| constants.rb:53:3:53:13 | FOURTY_FOUR | write | FOURTY_FOUR | ConstantAssignment |
| constants.rb:54:3:58:5 | ClassB | write | ClassB | ClassDeclaration |
| constants.rb:54:9:54:15 | ModuleB | read | ModuleB | ConstantReadAccess |
| constants.rb:54:27:54:30 | Base | read | Base | ConstantReadAccess |
| constants.rb:55:21:55:31 | FOURTY_FOUR | read | FOURTY_FOUR | ConstantReadAccess |
| constants.rb:56:5:56:15 | FOURTY_FOUR | write | FOURTY_FOUR | ConstantAssignment |
| constants.rb:57:21:57:31 | FOURTY_FOUR | read | FOURTY_FOUR | ConstantReadAccess |
| constants.rb:61:1:66:3 | Mod1 | write | Mod1 | ModuleDeclaration |
| constants.rb:62:3:64:5 | Mod3 | write | Mod3 | ModuleDeclaration |
| constants.rb:63:5:63:15 | FOURTY_FIVE | write | FOURTY_FIVE | ConstantAssignment |
| constants.rb:65:19:65:22 | Mod3 | read | Mod3 | ConstantReadAccess |
| constants.rb:65:19:65:35 | FOURTY_FIVE | read | FOURTY_FIVE | ConstantReadAccess |
| constants.rb:68:1:74:3 | Mod4 | write | Mod4 | ModuleDeclaration |
| constants.rb:69:11:69:14 | Mod1 | read | Mod1 | ConstantReadAccess |
| constants.rb:70:3:72:5 | Mod5 | write | Mod5 | ModuleDeclaration |
| constants.rb:70:10:70:13 | Mod3 | read | Mod3 | ConstantReadAccess |
| constants.rb:71:5:71:14 | FOURTY_SIX | write | FOURTY_SIX | ConstantAssignment |
| constants.rb:73:18:73:21 | Mod3 | read | Mod3 | ConstantReadAccess |
| constants.rb:73:18:73:33 | FOURTY_SIX | read | FOURTY_SIX | ConstantReadAccess |
getConst
| constants.rb:1:1:15:3 | ModuleA | CONST_B | constants.rb:6:15:6:23 | "const_b" |
| constants.rb:1:1:15:3 | ModuleA | FOURTY_FOUR | constants.rb:53:17:53:29 | "fourty-four" |
| constants.rb:2:5:4:7 | ModuleA::ClassA | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:31:1:33:3 | ModuleA::ClassD | FOURTY_TWO | constants.rb:32:16:32:17 | 42 |
| constants.rb:35:1:37:3 | ModuleA::ModuleC | FOURTY_THREE | constants.rb:36:18:36:19 | 43 |
| constants.rb:54:3:58:5 | ModuleA::ModuleB::ClassB | FOURTY_FOUR | constants.rb:56:19:56:20 | 44 |
| constants.rb:54:3:58:5 | ModuleA::ModuleB::ClassB | FOURTY_ONE | constants.rb:48:18:48:19 | 41 |
| constants.rb:62:3:64:5 | Mod1::Mod3 | FOURTY_FIVE | constants.rb:63:19:63:20 | 45 |
| constants.rb:70:3:72:5 | Mod1::Mod3::Mod5 | FOURTY_SIX | constants.rb:71:18:71:19 | 46 |
| file://:0:0:0:0 | Object | GREETING | constants.rb:17:12:17:64 | ... + ... |
lookupConst
| constants.rb:1:1:15:3 | ModuleA | CONST_B | constants.rb:6:15:6:23 | "const_b" |
| constants.rb:1:1:15:3 | ModuleA | FOURTY_FOUR | constants.rb:53:17:53:29 | "fourty-four" |
| constants.rb:2:5:4:7 | ModuleA::ClassA | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:2:5:4:7 | ModuleA::ClassA | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:8:5:14:7 | ModuleA::ModuleB | MAX_SIZE | constants.rb:37:30:37:33 | 1024 |
| constants.rb:9:9:10:11 | ModuleA::ModuleB::ClassB | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:8:5:14:7 | ModuleA::ModuleB | MAX_SIZE | constants.rb:39:30:39:33 | 1024 |
| constants.rb:12:9:13:11 | ModuleA::ModuleB::ClassC | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:31:1:32:3 | ModuleA::ClassD | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:31:1:32:3 | ModuleA::ClassD | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:31:1:33:3 | ModuleA::ClassD | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:31:1:33:3 | ModuleA::ClassD | FOURTY_TWO | constants.rb:32:16:32:17 | 42 |
| constants.rb:31:1:33:3 | ModuleA::ClassD | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:35:1:37:3 | ModuleA::ModuleC | FOURTY_THREE | constants.rb:36:18:36:19 | 43 |
| constants.rb:54:3:58:5 | ModuleA::ModuleB::ClassB | FOURTY_FOUR | constants.rb:56:19:56:20 | 44 |
| constants.rb:54:3:58:5 | ModuleA::ModuleB::ClassB | FOURTY_ONE | constants.rb:48:18:48:19 | 41 |
| constants.rb:54:3:58:5 | ModuleA::ModuleB::ClassB | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:62:3:64:5 | Mod1::Mod3 | FOURTY_FIVE | constants.rb:63:19:63:20 | 45 |
| constants.rb:70:3:72:5 | Mod1::Mod3::Mod5 | FOURTY_SIX | constants.rb:71:18:71:19 | 46 |
| file://:0:0:0:0 | Object | GREETING | constants.rb:17:12:17:64 | ... + ... |
constantValue
| constants.rb:17:22:17:45 | CONST_A | constants.rb:3:19:3:27 | "const_a" |
| constants.rb:17:49:17:64 | CONST_B | constants.rb:6:15:6:23 | "const_b" |
| constants.rb:23:18:23:25 | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:39:6:39:31 | MAX_SIZE | constants.rb:37:30:37:33 | 1024 |
| constants.rb:41:6:41:13 | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:42:6:42:15 | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:41:6:41:31 | MAX_SIZE | constants.rb:39:30:39:33 | 1024 |
| constants.rb:43:6:43:13 | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:44:6:44:15 | GREETING | constants.rb:17:12:17:64 | ... + ... |
| constants.rb:55:21:55:31 | FOURTY_FOUR | constants.rb:53:17:53:29 | "fourty-four" |
| constants.rb:55:21:55:31 | FOURTY_FOUR | constants.rb:56:19:56:20 | 44 |
| constants.rb:57:21:57:31 | FOURTY_FOUR | constants.rb:53:17:53:29 | "fourty-four" |
| constants.rb:57:21:57:31 | FOURTY_FOUR | constants.rb:56:19:56:20 | 44 |
| constants.rb:65:19:65:35 | FOURTY_FIVE | constants.rb:63:19:63:20 | 45 |
constantWriteAccessQualifiedName
| constants.rb:1:1:15:3 | ModuleA | ModuleA |
| constants.rb:2:5:4:7 | ClassA | ModuleA::ClassA |
@@ -65,6 +111,25 @@ constantWriteAccessQualifiedName
| constants.rb:12:9:13:11 | ClassC | ModuleA::ModuleB::ClassC |
| constants.rb:17:1:17:8 | GREETING | GREETING |
| constants.rb:20:5:20:9 | Names | Names |
| constants.rb:31:1:32:3 | ClassD | ClassD |
| constants.rb:34:1:35:3 | ModuleC | ModuleC |
| constants.rb:37:1:37:26 | MAX_SIZE | MAX_SIZE |
| constants.rb:31:1:33:3 | ClassD | ModuleA::ClassD |
| constants.rb:32:3:32:12 | FOURTY_TWO | ModuleA::ClassD::FOURTY_TWO |
| constants.rb:35:1:37:3 | ModuleC | ModuleA::ModuleC |
| constants.rb:36:3:36:14 | FOURTY_THREE | ModuleA::ModuleC::FOURTY_THREE |
| constants.rb:39:1:39:26 | MAX_SIZE | ModuleA::ModuleB::MAX_SIZE |
| constants.rb:46:1:50:3 | ModuleB | ModuleA::ModuleB |
| constants.rb:47:3:49:5 | ClassB | ModuleA::ModuleB::ClassB |
| constants.rb:48:5:48:14 | FOURTY_ONE | ModuleA::ModuleB::ClassB::FOURTY_ONE |
| constants.rb:52:1:59:3 | ModuleA | ModuleA |
| constants.rb:53:3:53:13 | FOURTY_FOUR | ModuleA::FOURTY_FOUR |
| constants.rb:54:3:58:5 | ClassB | ModuleA::ModuleB::ClassB |
| constants.rb:54:3:58:5 | ClassB | ModuleB::ClassB |
| constants.rb:56:5:56:15 | FOURTY_FOUR | ModuleA::ModuleB::ClassB::FOURTY_FOUR |
| constants.rb:56:5:56:15 | FOURTY_FOUR | ModuleB::ClassB::FOURTY_FOUR |
| constants.rb:61:1:66:3 | Mod1 | Mod1 |
| constants.rb:62:3:64:5 | Mod3 | Mod1::Mod3 |
| constants.rb:63:5:63:15 | FOURTY_FIVE | Mod1::Mod3::FOURTY_FIVE |
| constants.rb:68:1:74:3 | Mod4 | Mod4 |
| constants.rb:70:3:72:5 | Mod5 | Mod1::Mod3::Mod5 |
| constants.rb:70:3:72:5 | Mod5 | Mod3::Mod5 |
| constants.rb:71:5:71:14 | FOURTY_SIX | Mod1::Mod3::Mod5::FOURTY_SIX |
| constants.rb:71:5:71:14 | FOURTY_SIX | Mod3::Mod5::FOURTY_SIX |

View File

@@ -18,5 +18,5 @@ query Expr lookupConst(Module m, string name) { result = M::lookupConst(m, name)
query predicate constantValue(ConstantReadAccess a, Expr e) { e = a.getValue() }
query predicate constantWriteAccessQualifiedName(ConstantWriteAccess w, string qualifiedName) {
w.getQualifiedName() = qualifiedName
w.getAQualifiedName() = qualifiedName
}

View File

@@ -29,9 +29,11 @@ def foo
end
class ModuleA::ClassD < ModuleA::ClassA
FOURTY_TWO = 42
end
module ModuleA::ModuleC
FOURTY_THREE = 43
end
ModuleA::ModuleB::MAX_SIZE = 1024
@@ -40,3 +42,33 @@ puts ModuleA::ModuleB::MAX_SIZE
puts GREETING
puts ::GREETING
module ModuleA::ModuleB
class ClassB < Base
FOURTY_ONE = 41
end
end
module ModuleA
FOURTY_FOUR = "fourty-four"
class ModuleB::ClassB < Base
@@fourty_four = FOURTY_FOUR # refers to ::ModuleA::FOURTY_FOUR
FOURTY_FOUR = 44
@@fourty_four = FOURTY_FOUR # refers to ::ModuleA::ModuleB::ClassB::FOURTY_FOUR
end
end
module Mod1
module Mod3
FOURTY_FIVE = 45
end
@@fourty_five = Mod3::FOURTY_FIVE
end
module Mod4
include Mod1
module Mod3::Mod5
FOURTY_SIX = 46
end
@@fourty_six = Mod3::FOURTY_SIX
end