@@ -63,11 +63,17 @@ class ActiveRecordModelClass extends ClassDeclaration {
63
63
)
64
64
}
65
65
66
+ // Gets the class declaration for this class and all of its super classes
67
+ private ModuleBase getAllClassDeclarations ( ) {
68
+ result = this .getModule ( ) .getSuperClass * ( ) .getADeclaration ( )
69
+ }
70
+
66
71
/**
67
72
* Gets methods defined in this class that may access a field from the database.
68
73
*/
69
74
Method methodMayAccessField ( ) {
70
- result = this .getAMethod ( ) and
75
+ // It's a method on this class or one of its super classes
76
+ result = this .getAllClassDeclarations ( ) .getAMethod ( ) and
71
77
// There is a value that can be returned by this method which may include field data
72
78
exists ( DataFlow:: Node returned , ActiveRecordInstanceMethodCall cNode , MethodCall c |
73
79
exprNodeReturnedFrom ( returned , result ) and
@@ -77,10 +83,10 @@ class ActiveRecordModelClass extends ClassDeclaration {
77
83
// The referenced method is not built-in, and...
78
84
not isBuiltInMethodForActiveRecordModelInstance ( c .getMethodName ( ) ) and
79
85
(
80
- // TODO: this would be more accurate if we also checked methods defined in
81
- // super classes and mixins
82
- // ...There is no matching method definition in the class, or...
83
- not exists ( cNode . getInstance ( ) . getClass ( ) . getMethod ( c . getMethodName ( ) ) )
86
+ // ...The receiver does not have a matching method definition, or...
87
+ not exists (
88
+ cNode . getInstance ( ) . getClass ( ) . getAllClassDeclarations ( ) . getMethod ( c . getMethodName ( ) )
89
+ )
84
90
or
85
91
// ...the called method can access a field
86
92
c .getATarget ( ) = cNode .getInstance ( ) .getClass ( ) .methodMayAccessField ( )
0 commit comments