@@ -64,6 +64,13 @@ private module Input1 implements InputSig1<Location> {
6464 kind = 3 and
6565 tp0 = TUnknownTypeTypeParameter ( id1 ) and
6666 id2 = 0
67+ or
68+ kind = 4 and
69+ exists ( ClassLikeDeclaration c |
70+ tp0 = TParentTypeParameterType ( c ) and
71+ id1 = idOfTypeParameterAstNode ( c ) and
72+ id2 = 0
73+ )
6774 |
6875 tp0 order by kind , id1 , id2
6976 )
@@ -389,9 +396,6 @@ module Input3 implements InputSig3 {
389396 Unified:: Callable getCallable ( ) { result = c }
390397
391398 override TypeMention getDeclaringType ( ) {
392- result = c .( EnumConstructor ) .getEnum ( ) .getNameNode ( )
393- or
394- not c instanceof EnumConstructor and
395399 exists ( ClassLikeDeclaration cls |
396400 c = cls .getAMember ( ) and
397401 result = getClassLikeDeclarationTypeMention ( cls )
@@ -405,9 +409,9 @@ module Input3 implements InputSig3 {
405409 or
406410 result = c .( FunctionDeclaration ) .getNameNode ( )
407411 or
408- result = c .( EnumConstructor ) . getEnclosingClass ( ) .getNameNode ( )
412+ result = c .( EnumCaseConstructor ) . getEnumCaseClass ( ) .getNameNode ( )
409413 or
410- not c instanceof EnumConstructor and
414+ not c instanceof EnumCaseConstructor and
411415 result = c .( ConstructorDeclaration ) .getNameNode ( )
412416 }
413417
@@ -492,15 +496,17 @@ module Input3 implements InputSig3 {
492496 }
493497
494498 Callable getTargetViaStaticNameBinding ( ) {
495- exists ( NameBinding b | b = getStaticBindingTargetFromRef ( this . getCallee ( ) ) |
499+ exists ( NameBinding b |
496500 // object creation (including enum constructors): `String(42)`, `Optional.Some(42)`
501+ b = getTypeFromRefAliasesResolved ( this .getCallee ( ) ) and
497502 exists ( ClassLikeDeclaration cls |
498503 cls .getNameNode ( ) = b and
499504 result .isInstanceMemberOf ( cls , _) and
500505 result .asCallable ( ) instanceof ConstructorDeclaration
501506 )
502507 or
503508 // call without explicit receiver: `foo(42)`
509+ b = getStaticBindingTargetFromRef ( this .getCallee ( ) ) and
504510 result .getNameNode ( ) = b
505511 )
506512 }
@@ -659,10 +665,20 @@ module Input3 implements InputSig3 {
659665 result = getQualifierTypeMention ( invocation )
660666 }
661667
662- private predicate constructionReceiver ( Invocation i , Callable constructor , Expr receiver ) {
663- constructor = i .getTargetImpl ( _) and
664- constructor .asCallable ( ) instanceof ConstructorDeclaration and
665- receiver = i .getArgument ( 0 )
668+ private predicate constructionReceiver (
669+ Invocation i , Callable constructor , Expr receiver , TypePath enumPrefixPath
670+ ) {
671+ exists ( ConstructorDeclaration cd |
672+ constructor = i .getTargetImpl ( _) and
673+ cd = constructor .asCallable ( ) and
674+ receiver = i .getArgument ( 0 )
675+ |
676+ enumPrefixPath =
677+ TypePath:: singleton ( TParentTypeParameterType ( cd .( EnumCaseConstructor ) .getEnumCaseClass ( ) ) )
678+ or
679+ not cd instanceof EnumCaseConstructor and
680+ enumPrefixPath .isEmpty ( )
681+ )
666682 }
667683
668684 /**
@@ -696,11 +712,15 @@ module Input3 implements InputSig3 {
696712 M3:: ContextualTyping:: ContextualReturnType< ContextualConstructorReturnTypeInput > ;
697713
698714 private predicate needsContextualTyping ( Invocation i , TypePath path ) {
699- exists ( Callable constructor , Expr receiver , ClassLikeDeclarationType receiverType |
700- constructionReceiver ( i , constructor , receiver ) and
701- receiverType = inferType ( receiver )
715+ exists (
716+ Callable constructor , Expr receiver , TypePath enumPrefixPath ,
717+ ClassLikeDeclarationType receiverType , TypePath path0
718+ |
719+ constructionReceiver ( i , constructor , receiver , enumPrefixPath ) and
720+ receiverType = inferType ( receiver ) and
721+ path = path0 .stripPrefix ( enumPrefixPath )
702722 |
703- ContextualConstructorReturnType:: needsContextualTyping ( i , path ) and
723+ ContextualConstructorReturnType:: needsContextualTyping ( i , path0 ) and
704724 receiverType = constructor .getDeclaringType ( ) .getType ( )
705725 or
706726 // inherited constructor
@@ -710,18 +730,19 @@ module Input3 implements InputSig3 {
710730 |
711731 declType = constructor .getDeclaringType ( ) .getType ( ) and
712732 BaseTypes:: rootTypesSatisfaction ( receiverType , declType , abs , _, constraint ) and
713- path = TypePath:: singleton ( tp )
733+ tp =
734+ getClassLikeDeclarationTypeMention ( receiverType .getClassLikeDeclaration ( ) )
735+ .getTypeAt ( path0 )
714736 |
715737 // `A<T> : B<T>`
716- exists ( TypePath path0 |
717- BaseTypes:: conditionSatisfiesConstraintTypeAt ( abs , _, constraint , path0 , tp ) and
718- ContextualConstructorReturnType:: needsContextualTyping ( i , path0 )
738+ exists ( TypePath path1 |
739+ BaseTypes:: conditionSatisfiesConstraintTypeAt ( abs , _, constraint , path1 , tp ) and
740+ ContextualConstructorReturnType:: needsContextualTyping ( i , path1 )
719741 )
720742 or
721743 // `A<T> : B`
722- tp = receiverType .getATypeParameter ( ) and
723744 not BaseTypes:: conditionSatisfiesConstraintTypeAt ( abs , _, constraint , _, tp ) and
724- not exists ( Type t | t = i .getTypeQualifier ( path ) and not t instanceof PseudoType )
745+ not exists ( Type t | t = i .getTypeQualifier ( path0 ) and not t instanceof PseudoType )
725746 )
726747 )
727748 }
@@ -734,8 +755,7 @@ module Input3 implements InputSig3 {
734755 * as well as calls receivers, `self.init(0)` or `super.init(0)`.
735756 */
736757 predicate step ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
737- constructionReceiver ( n2 , _, n1 ) and
738- prefix1 .isEmpty ( ) and
758+ constructionReceiver ( n2 , _, n1 , prefix1 ) and
739759 prefix2 .isEmpty ( )
740760 }
741761
0 commit comments