@@ -144,7 +144,9 @@ class StructType extends Type, TStruct {
144144 // todo: assumes all `impl` blocks are in scope
145145 exists ( ImplItemNode i |
146146 struct = i .resolveSelfTy ( ) and
147- result = i .getASuccessor ( name )
147+ result = i .getASuccessor ( name ) and
148+ // todo: generics are not supported
149+ not i .getSelfPath ( ) .getPart ( ) .hasGenericArgList ( )
148150 )
149151 }
150152
@@ -173,7 +175,9 @@ class EnumType extends Type, TEnum {
173175 // todo: assumes all `impl` blocks are in scope
174176 exists ( ImplItemNode i |
175177 enum = i .resolveSelfTy ( ) and
176- result = i .getASuccessor ( name )
178+ result = i .getASuccessor ( name ) and
179+ // todo: generics are not supported
180+ not i .getSelfPath ( ) .getPart ( ) .hasGenericArgList ( )
177181 )
178182 }
179183
@@ -386,34 +390,6 @@ private module BaseTypes {
386390 )
387391 }
388392
389- // pragma[nomagic]
390- // predicate arrayBaseTypeHasTypeParameterAt(Type base, TypePath path) {
391- // exists(UnboundType::TsIListInterfaceType immediateBase |
392- // base = immediateBase and
393- // path = "0"
394- // or
395- // // transitive base class
396- // exists(TypeRepr baseTypeMention |
397- // baseTypeMentionHasTypeParameterAt(immediateBase, baseTypeMention, path, _) and
398- // base = baseTypeMention.getType()
399- // )
400- // )
401- // }
402- // pragma[nomagic]
403- // predicate arrayBaseTypeHasNonTypeParameterAt(Type base, TypePath path, Type t) {
404- // not t instanceof TypeParameter and
405- // exists(UnboundType::TsIListInterfaceType immediateBase |
406- // base = immediateBase and
407- // t = base and
408- // path = ""
409- // or
410- // // transitive base class
411- // exists(TypeRepr baseTypeMention |
412- // baseTypeMentionHasNonTypeParameterAt(immediateBase, baseTypeMention, path, t) and
413- // base = baseTypeMention.getType()
414- // )
415- // )
416- // }
417393 /**
418394 * Holds if `base` is a (transitive) base type mention of `sub`, and
419395 * non-type-parameter `t` is mentioned (implicitly) at `path` inside `base`.
@@ -534,7 +510,10 @@ private signature module MatchingInputSig {
534510 }
535511
536512 bindingset [ this ]
537- class Pos ;
513+ class Pos {
514+ bindingset [ this ]
515+ string toString ( ) ;
516+ }
538517
539518 Pos getReturnPos ( ) ;
540519
@@ -614,14 +593,26 @@ private module Matching<MatchingInputSig Input> {
614593 }
615594
616595 private module BaseTypeAtInput implements BaseTypeAtInputSig {
617- newtype Node =
618- additional MkNode ( Access a , Pos pos ) {
596+ private newtype TNode =
597+ MkNode ( Access a , Pos pos ) {
619598 exists ( Decl target |
620599 argumentTypeAt ( a , pos , target , _, _) and
621600 declType ( target , _, _, any ( TypeParameter tp ) )
622601 )
623602 }
624603
604+ additional Node mkNode ( Access a , Pos pos ) { result = MkNode ( a , pos ) }
605+
606+ class Node extends MkNode {
607+ Access getAccess ( ) { this = MkNode ( result , _) }
608+
609+ Pos getPos ( ) { this = MkNode ( _, result ) }
610+
611+ string toString ( ) { result = this .getAccess ( ) .toString ( ) + ", " + this .getPos ( ) .toString ( ) }
612+
613+ Location getLocation ( ) { result = this .getAccess ( ) .getLocation ( ) }
614+ }
615+
625616 Type resolveType ( Node n , TypePath path ) {
626617 exists ( Access a , Pos pos |
627618 n = MkNode ( a , pos ) and
@@ -648,7 +639,7 @@ private module Matching<MatchingInputSig Input> {
648639 ) {
649640 exists ( TypeRepr_ tm |
650641 target ( a , target ) and
651- NodeHasBaseTypeAt< BaseTypeAtInput > :: hasBaseType ( BaseTypeAtInput:: MkNode ( a , pos ) , tm , path , t ) and
642+ NodeHasBaseTypeAt< BaseTypeAtInput > :: hasBaseType ( BaseTypeAtInput:: mkNode ( a , pos ) , tm , path , t ) and
652643 base = tm .resolveType ( )
653644 )
654645 // or
@@ -740,10 +731,21 @@ private Type resolveVariableType(AstNode n, TypePath path) {
740731}
741732
742733pragma [ nomagic]
743- private Type resolveSelfType ( Impl i , TypePath path ) {
734+ private Type resolveImplSelfType ( Impl i , TypePath path ) {
744735 result = i .getSelfTy ( ) .( TypeRepr_ ) .resolveTypeAt ( path )
745736}
746737
738+ pragma [ nomagic]
739+ private Type resolveTraitSelfType ( Trait t , TypePath path ) {
740+ result = TTrait ( t ) and
741+ path .isEmpty ( )
742+ or
743+ exists ( int i |
744+ result = TTypeParameter ( t .getGenericParamList ( ) .getTypeParam ( i ) ) and
745+ path = typePath ( i )
746+ )
747+ }
748+
747749pragma [ nomagic]
748750private Type resolveTargetTyped ( AstNode n , TypePath path ) {
749751 isTargetTyped ( n ) and
@@ -753,9 +755,13 @@ private Type resolveTargetTyped(AstNode n, TypePath path) {
753755 result = resolveType ( let .getInitializer ( ) , path )
754756 )
755757 or
756- exists ( ImplItemNode i , Function f , SelfParam p , TypePath suffix , Type res |
758+ exists ( ItemNode i , Function f , SelfParam p , TypePath suffix , Type res |
757759 n = p and
758- res = resolveSelfType ( i , suffix ) and
760+ (
761+ res = resolveImplSelfType ( i , suffix )
762+ or
763+ res = resolveTraitSelfType ( i , suffix )
764+ ) and
759765 f = i .getASuccessor ( _) and
760766 p = f .getParamList ( ) .getSelfParam ( )
761767 |
0 commit comments