@@ -63,14 +63,27 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
6363
6464 DataFlow:: MethodNode getNode ( ) { result = this }
6565
66- override string getName ( ) { result = super .getMethodName ( ) }
66+ override string getName ( ) {
67+ result = super .getMethodName ( ) and not this .isConstructor ( )
68+ or
69+ // Constructors are modeled as Type!#new rather than Type#initialize
70+ result = "new" and this .isConstructor ( )
71+ }
6772
6873 /**
6974 * Gets the unbound type name of this endpoint.
7075 */
7176 override string getType ( ) {
7277 result =
73- any ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( this .getName ( ) ) = this ) .getQualifiedName ( ) or
78+ any ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( this .getName ( ) ) = this ) .getQualifiedName ( ) and
79+ not this .isConstructor ( )
80+ or
81+ // Constructors are modeled on `Type!`, not on `Type`
82+ result =
83+ any ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( super .getMethodName ( ) ) = this )
84+ .getQualifiedName ( ) + "!" and
85+ this .isConstructor ( )
86+ or
7487 result =
7588 any ( DataFlow:: ModuleNode m | m .getOwnSingletonMethod ( this .getName ( ) ) = this )
7689 .getQualifiedName ( ) + "!"
@@ -136,6 +149,14 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
136149 or
137150 not this .isSupported ( ) and result = ""
138151 }
152+
153+ /**
154+ * Holds if this method is a constructor for a module.
155+ */
156+ private predicate isConstructor ( ) {
157+ super .getMethodName ( ) = "initialize" and
158+ exists ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( super .getMethodName ( ) ) = this )
159+ }
139160}
140161
141162string methodClassification ( Call method ) {
0 commit comments