@@ -68,14 +68,27 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
6868
6969 DataFlow:: MethodNode getNode ( ) { result = this }
7070
71- override string getName ( ) { result = super .getMethodName ( ) }
71+ override string getName ( ) {
72+ result = super .getMethodName ( ) and this .isConstructor ( ) = false
73+ or
74+ // Constructors are modeled as Type!#new rather than Type#initialize
75+ result = "new" and this .isConstructor ( ) = true
76+ }
7277
7378 /**
7479 * Gets the unbound type name of this endpoint.
7580 */
7681 override string getType ( ) {
7782 result =
78- any ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( this .getName ( ) ) = this ) .getQualifiedName ( ) or
83+ any ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( this .getName ( ) ) = this ) .getQualifiedName ( ) and
84+ this .isConstructor ( ) = false
85+ or
86+ // Constructors are modeled on `Type!`, not on `Type`
87+ result =
88+ any ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( super .getMethodName ( ) ) = this )
89+ .getQualifiedName ( ) + "!" and
90+ this .isConstructor ( ) = true
91+ or
7992 result =
8093 any ( DataFlow:: ModuleNode m | m .getOwnSingletonMethod ( this .getName ( ) ) = this )
8194 .getQualifiedName ( ) + "!"
@@ -141,6 +154,17 @@ class MethodEndpoint extends Endpoint instanceof DataFlow::MethodNode {
141154 or
142155 not this .isSupported ( ) and result = ""
143156 }
157+
158+ /**
159+ * Holds if this method is a constructor for a module.
160+ */
161+ private boolean isConstructor ( ) {
162+ if
163+ super .getMethodName ( ) = "initialize" and
164+ exists ( DataFlow:: ModuleNode m | m .getOwnInstanceMethod ( super .getMethodName ( ) ) = this )
165+ then result = true
166+ else result = false
167+ }
144168}
145169
146170string methodClassification ( Call method ) {
0 commit comments