@@ -29,7 +29,26 @@ newtype TType =
2929abstract class Type extends TType {
3030 /** Gets the method `name` belonging to this type, if any. */
3131 pragma [ nomagic]
32- abstract Function getMethod ( string name ) ;
32+ final Function getMethod ( string name ) {
33+ result = this .getAMethod ( name ) and
34+ (
35+ // when a method exists in both source code and in library code, it is because
36+ // we also extracted the source code as library code, and hence we only want
37+ // the method from source code
38+ result .fromSource ( )
39+ or
40+ not this .getAMethod ( name ) .fromSource ( )
41+ )
42+ }
43+
44+ /**
45+ * Gets a method `name` belonging to this type, if any.
46+ *
47+ * Multiple methods may exist with the same name when it exists in both
48+ * source code and in library code.
49+ */
50+ pragma [ nomagic]
51+ abstract Function getAMethod ( string name ) ;
3352
3453 /** Gets the struct field `name` belonging to this type, if any. */
3554 pragma [ nomagic]
@@ -75,7 +94,7 @@ abstract private class StructOrEnumType extends Type {
7594 abstract ItemNode asItemNode ( ) ;
7695
7796 pragma [ nomagic]
78- private Function getMethodCand ( ImplOrTraitItemNode impl , string name ) {
97+ private Function getAMethodCand ( ImplOrTraitItemNode impl , string name ) {
7998 result = this .asItemNode ( ) .getASuccessor ( name ) and
8099 result = impl .getAnAssocItem ( ) and
81100 (
@@ -86,17 +105,17 @@ abstract private class StructOrEnumType extends Type {
86105 }
87106
88107 pragma [ nomagic]
89- private Function getImplMethod ( ImplOrTraitItemNode impl , string name ) {
90- result = this .getMethodCand ( impl , name ) and
108+ private Function getAnImplMethod ( ImplOrTraitItemNode impl , string name ) {
109+ result = this .getAMethodCand ( impl , name ) and
91110 impl = any ( Impl i | not i .hasTrait ( ) )
92111 }
93112
94- final override Function getMethod ( string name ) {
95- result = this .getImplMethod ( _, name )
113+ final override Function getAMethod ( string name ) {
114+ result = this .getAnImplMethod ( _, name )
96115 or
97116 // methods from `impl` blocks shadow functions from `impl Trait` blocks
98- result = this .getMethodCand ( _, name ) and
99- not exists ( this .getImplMethod ( _, name ) )
117+ result = this .getAMethodCand ( _, name ) and
118+ not exists ( this .getAnImplMethod ( _, name ) )
100119 }
101120
102121 /** Gets all of the fully parametric `impl` blocks that target this type. */
@@ -154,7 +173,7 @@ class TraitType extends Type, TTrait {
154173
155174 TraitType ( ) { this = TTrait ( trait ) }
156175
157- override Function getMethod ( string name ) { result = trait .( ItemNode ) .getASuccessor ( name ) }
176+ override Function getAMethod ( string name ) { result = trait .( ItemNode ) .getASuccessor ( name ) }
158177
159178 override StructField getStructField ( string name ) { none ( ) }
160179
@@ -236,7 +255,7 @@ class ImplType extends Type, TImpl {
236255
237256 ImplType ( ) { this = TImpl ( impl ) }
238257
239- override Function getMethod ( string name ) { result = impl .( ItemNode ) .getASuccessor ( name ) }
258+ override Function getAMethod ( string name ) { result = impl .( ItemNode ) .getASuccessor ( name ) }
240259
241260 override StructField getStructField ( string name ) { none ( ) }
242261
@@ -263,7 +282,7 @@ class ImplType extends Type, TImpl {
263282class ArrayType extends Type , TArrayType {
264283 ArrayType ( ) { this = TArrayType ( ) }
265284
266- override Function getMethod ( string name ) { none ( ) }
285+ override Function getAMethod ( string name ) { none ( ) }
267286
268287 override StructField getStructField ( string name ) { none ( ) }
269288
@@ -289,7 +308,7 @@ class ArrayType extends Type, TArrayType {
289308class RefType extends Type , TRefType {
290309 RefType ( ) { this = TRefType ( ) }
291310
292- override Function getMethod ( string name ) { none ( ) }
311+ override Function getAMethod ( string name ) { none ( ) }
293312
294313 override StructField getStructField ( string name ) { none ( ) }
295314
@@ -334,7 +353,7 @@ class TypeParamTypeParameter extends TypeParameter, TTypeParamTypeParameter {
334353
335354 TypeParam getTypeParam ( ) { result = typeParam }
336355
337- override Function getMethod ( string name ) {
356+ override Function getAMethod ( string name ) {
338357 // NOTE: If the type parameter has trait bounds, then this finds methods
339358 // on the bounding traits.
340359 result = typeParam .( ItemNode ) .getASuccessor ( name )
@@ -393,7 +412,7 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
393412
394413 int getIndex ( ) { traitAliasIndex ( _, result , typeAlias ) }
395414
396- override Function getMethod ( string name ) { none ( ) }
415+ override Function getAMethod ( string name ) { none ( ) }
397416
398417 override string toString ( ) { result = typeAlias .getName ( ) .getText ( ) }
399418
@@ -404,7 +423,7 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
404423
405424/** An implicit reference type parameter. */
406425class RefTypeParameter extends TypeParameter , TRefTypeParameter {
407- override Function getMethod ( string name ) { none ( ) }
426+ override Function getAMethod ( string name ) { none ( ) }
408427
409428 override string toString ( ) { result = "&T" }
410429
@@ -427,7 +446,7 @@ class SelfTypeParameter extends TypeParameter, TSelfTypeParameter {
427446
428447 override TypeMention getABaseTypeMention ( ) { result = trait }
429448
430- override Function getMethod ( string name ) {
449+ override Function getAMethod ( string name ) {
431450 // The `Self` type parameter is an implementation of the trait, so it has
432451 // all the trait's methods.
433452 result = trait .( ItemNode ) .getASuccessor ( name )
0 commit comments