@@ -874,6 +874,9 @@ private module RecordFieldMatchingInput implements MatchingInputSig {
874874 t = TStruct ( decl ) and
875875 path .isEmpty ( )
876876 or
877+ t = TEnum ( decl .( VariantDecl ) .getEnum ( ) ) and
878+ path .isEmpty ( )
879+ or
877880 exists ( int i |
878881 t = decl .getTypeParameter ( i ) and
879882 path = typePath ( i )
@@ -886,6 +889,13 @@ private module RecordFieldMatching = Matching<RecordFieldMatchingInput>;
886889private Type resolveRecordExprType ( RecordExpr re , TypePath path ) {
887890 result = re .getPath ( ) .( Path_ ) .resolveTypeAt ( path )
888891 or
892+ exists ( Enum e , Variant v |
893+ v = resolvePath ( re .getPath ( ) ) and
894+ v = e .getVariantList ( ) .getAVariant ( ) and
895+ result = TEnum ( e ) and
896+ path .isEmpty ( )
897+ )
898+ or
889899 // result = resolveFunctionReturnType(call.getStaticTarget(), path)
890900 result = RecordFieldMatching:: resolveAccess ( re , "(return)" , path )
891901}
@@ -898,10 +908,88 @@ private module FunctionMatchingInput implements MatchingInputSig {
898908
899909 Pos getReturnPos ( ) { result = - 2 }
900910
901- class Decl extends Function {
902- TypeParameter getTypeParameter ( int i ) {
911+ // class Decl extends Function {
912+ // TypeParameter getTypeParameter(int i) {
913+ // result.getTypeParam() = this.getGenericParamList().getTypeParam(i)
914+ // }
915+ // }
916+ abstract class Decl extends AstNode {
917+ abstract TypeParameter getTypeParameter ( int i ) ;
918+
919+ abstract Type getParameterType ( int pos , TypePath path ) ;
920+
921+ abstract Type getReturnType ( TypePath path ) ;
922+ }
923+
924+ private class StructDecl extends Decl , Struct {
925+ override TypeParameter getTypeParameter ( int i ) {
926+ result .getTypeParam ( ) = this .getGenericParamList ( ) .getTypeParam ( i )
927+ }
928+
929+ override Type getParameterType ( int pos , TypePath path ) {
930+ result = this .getTupleField ( pos ) .getTypeRepr ( ) .( TypeRepr_ ) .resolveTypeAt ( path )
931+ }
932+
933+ override Type getReturnType ( TypePath path ) {
934+ result = TStruct ( this ) and
935+ path .isEmpty ( )
936+ or
937+ exists ( int i |
938+ result = TTypeParameter ( this .getGenericParamList ( ) .getTypeParam ( i ) ) and
939+ path = typePath ( i )
940+ )
941+ }
942+ }
943+
944+ private class VariantDecl extends Decl , Variant {
945+ Enum getEnum ( ) { result .getVariantList ( ) .getAVariant ( ) = this }
946+
947+ override TypeParameter getTypeParameter ( int i ) {
948+ result .getTypeParam ( ) = this .getEnum ( ) .getGenericParamList ( ) .getTypeParam ( i )
949+ }
950+
951+ override Type getParameterType ( int pos , TypePath path ) {
952+ result = this .getTupleField ( pos ) .getTypeRepr ( ) .( TypeRepr_ ) .resolveTypeAt ( path )
953+ }
954+
955+ override Type getReturnType ( TypePath path ) {
956+ exists ( Enum enum | enum = this .getEnum ( ) |
957+ result = TEnum ( enum ) and
958+ path .isEmpty ( )
959+ or
960+ exists ( int i |
961+ result = TTypeParameter ( enum .getGenericParamList ( ) .getTypeParam ( i ) ) and
962+ path = typePath ( i )
963+ )
964+ )
965+ }
966+ }
967+
968+ private class FunctionDecl extends Decl , Function {
969+ override TypeParameter getTypeParameter ( int i ) {
903970 result .getTypeParam ( ) = this .getGenericParamList ( ) .getTypeParam ( i )
904971 }
972+
973+ override Type getParameterType ( int pos , TypePath path ) {
974+ exists ( TypeRepr_ tp |
975+ paramTyped ( this .getParamList ( ) .getParam ( pos ) , _, tp )
976+ or
977+ selfParamTyped ( this .getParamList ( ) .getSelfParam ( ) , tp ) and
978+ pos = - 1
979+ |
980+ result = tp .resolveTypeAt ( path )
981+ )
982+ or
983+ exists ( SelfParam self |
984+ self = this .getParamList ( ) .getSelfParam ( ) and
985+ pos = - 1 and
986+ result = resolveTargetTyped ( self , path )
987+ )
988+ }
989+
990+ override Type getReturnType ( TypePath path ) {
991+ result = this .getRetType ( ) .getTypeRepr ( ) .( TypeRepr_ ) .resolveTypeAt ( path )
992+ }
905993 }
906994
907995 class Access extends CallExprBase {
@@ -923,14 +1011,20 @@ private module FunctionMatchingInput implements MatchingInputSig {
9231011 predicate noExplicitTypeArguments ( ) { not exists ( this .getTypeArg ( _) ) }
9241012 }
9251013
926- predicate target ( Access a , Decl target ) { target = a .getStaticTarget ( ) }
1014+ predicate target ( Access a , Decl target ) {
1015+ target = a .getStaticTarget ( )
1016+ or
1017+ target = a .( CallExpr ) .getStruct ( )
1018+ or
1019+ target = a .( CallExpr ) .getVariant ( )
1020+ }
9271021
9281022 private AstNode getExplicitArgument ( Access a , int pos ) {
9291023 exists ( int offset , Decl target |
9301024 result = a .getArgList ( ) .getArg ( pos + offset ) and
9311025 target ( a , target )
9321026 |
933- if target .getParamList ( ) .hasSelfParam ( ) and not a instanceof MethodCallExpr
1027+ if target .( Function ) . getParamList ( ) .hasSelfParam ( ) and not a instanceof MethodCallExpr
9341028 then offset = 1
9351029 else offset = 0
9361030 )
@@ -974,26 +1068,11 @@ private module FunctionMatchingInput implements MatchingInputSig {
9741068 }
9751069
9761070 predicate parameterType ( Decl decl , int pos , TypePath path , Type t ) {
977- exists ( TypeRepr_ tp |
978- paramTyped ( decl .getParamList ( ) .getParam ( pos ) , _, tp )
979- or
980- selfParamTyped ( decl .getParamList ( ) .getSelfParam ( ) , tp ) and
981- pos = - 1
982- |
983- t = tp .resolveTypeAt ( path )
984- )
985- or
986- exists ( SelfParam self |
987- self = decl .getParamList ( ) .getSelfParam ( ) and
988- pos = - 1 and
989- t = resolveTargetTyped ( self , path )
990- )
1071+ t = decl .getParameterType ( pos , path )
9911072 }
9921073
9931074 pragma [ nomagic]
994- predicate declType ( Decl decl , TypePath path , Type t ) {
995- t = decl .getRetType ( ) .getTypeRepr ( ) .( TypeRepr_ ) .resolveTypeAt ( path )
996- }
1075+ predicate declType ( Decl decl , TypePath path , Type t ) { t = decl .getReturnType ( path ) }
9971076}
9981077
9991078private module FunctionMatching = Matching< FunctionMatchingInput > ;
0 commit comments