Skip to content

Conversation

johannescoetzee
Copy link
Contributor

In several languages (at least PHP, C++, and Java), static methods are inherited as well as instance methods, e.g.

class Foo {
  public static int foo(int x) { return x; }
}

class Bar extends Foo { }

public class Test {
  public int method(int p1) {
    return Bar.foo(p1);
  }
}

In this example, the methodFullName of the foo call will be Bar.foo:int(int) while the fullName of the method actually being called is Foo.foo:int(int). This call then isn't linked correctly since we assume for static calls the fullName of the call and method are the same.

This issue can be fixed during AST creation if we have the type information available (probably Java, probably not C++ and definitely not PHP). To fix this in general, we need to know the base type on which the method is being called so that we can search the ancestor types for the method declaration if necessary, so this PR adds the STATIC_BASE_TYPE field to keep track of this information. Before call linking, we can use this information to look up the corresponding type decl which would give us the information we need. The call METHOD_FULL_NAME can then be overwritten when we know the correct name.

The STATIC_BASE_TYPE property name is just an idea and I'm open to changing it if someone has a better one :)

Other ideas @ml86 and I discussed for how to represent this were:

  • Adding a RECEIVER edge to a TYPE_REF for relevant static calls. The issue is that TYPE_REFs are a starting point for some dataflow steps, so without special handling this could impact performance.
  • Adding a new node or edge type containing the information. This is potentially more flexible if we realize we need more information to handle special cases in the future, but this is unlikely since the use of this field will be limited to static calls, which are relatively simple. We would ideally also remove these nodes/edges from the CPG after processing them, which can be slow.

val AstParentType = 56
val AstParentFullName = 57
val DependencyGroupId = 58
val StaticBaseType = 59
Copy link
Contributor Author

@johannescoetzee johannescoetzee Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose this arbitrarily since I don't know if this has any special meaning. I'm happy to change it if needs be

Edit: word from Michael is that it needs to be unique across the closed source schema too, but I checked and it looks good

@johannescoetzee johannescoetzee merged commit 05a7a7c into master Jul 23, 2025
1 check passed
@johannescoetzee johannescoetzee deleted the johannes/add-static-base-type-property branch July 23, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants