@@ -24,15 +24,21 @@ private string getShortConstructorName(CallExpr call) {
2424 // so do not do this for Identifiers
2525}
2626
27+ /**
28+ * Holds if `call` targets a member called `name` and has the given `arity`.
29+ */
30+ pragma [ nomagic]
31+ private predicate callSiteHasSignature ( CallExpr call , string name , int arity ) {
32+ name = call .getCallee ( ) .( MemberAccessExpr ) .getMemberName ( ) and
33+ arity = call .getNumberOfArguments ( )
34+ }
35+
2736/**
2837 * Holds if a constructor pattern has the given short `name` and `arity`.
2938 */
3039pragma [ nomagic]
3140private predicate isSignatureUsedInConstructorPattern ( string name , int arity ) {
32- exists ( ConstructorPattern ctor |
33- name = getShortConstructorName ( ctor ) and
34- arity = ctor .getNumberOfArguments ( )
35- )
41+ callSiteHasSignature ( any ( ConstructorPattern p ) , name , arity )
3642}
3743
3844/** Holds if `callable` is an enum-case constructor */
@@ -50,12 +56,13 @@ private predicate assumeResolvesToEnumCaseConstructor(CallExpr call) {
5056 isEnumCaseConstructor ( T:: resolveCallTarget ( call ) )
5157 or
5258 // If the `E` in `E.foo(...)` could not be resolved, check if the name `foo` matches a constructor pattern.
53- exists ( MemberAccessExpr callee , Expr base |
59+ exists ( MemberAccessExpr callee , Expr base , string name , int arity |
5460 callee = call .getCallee ( ) and
5561 base = callee .getBase ( ) and
5662 not exists ( NameBinding:: getStaticBindingTargetFromRef ( base ) ) and
5763 not exists ( T:: inferType ( base ) ) and
58- isSignatureUsedInConstructorPattern ( callee .getMemberName ( ) , call .getNumberOfArguments ( ) )
64+ callSiteHasSignature ( call , name , arity ) and
65+ isSignatureUsedInConstructorPattern ( name , arity )
5966 )
6067}
6168
0 commit comments