@@ -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,21 @@ module Input3 implements InputSig3 {
492496 }
493497
494498 Callable getTargetViaStaticNameBinding ( ) {
495- exists ( NameBinding b | b = getStaticBindingTargetFromRef ( this .getCallee ( ) ) |
496- // object creation (including enum constructors): `String(42)`, `Optional.Some(42)`
497- exists ( ClassLikeDeclaration cls |
498- cls .getNameNode ( ) = b and
499- result .isInstanceMemberOf ( cls , _) and
500- result .asCallable ( ) instanceof ConstructorDeclaration
501- )
502- or
503- // call without explicit receiver: `foo(42)`
499+ // object creation (including enum constructors): `String(42)`, `Optional.Some(42)`
500+ exists ( ClassLikeDeclaration cls |
501+ cls =
502+ this .getCallee ( )
503+ .( TypeMention )
504+ .getType ( )
505+ .( ClassLikeDeclarationType )
506+ .getClassLikeDeclaration ( ) and
507+ result .isInstanceMemberOf ( cls , _) and
508+ result .asCallable ( ) instanceof ConstructorDeclaration
509+ )
510+ or
511+ // call without explicit receiver: `foo(42)`
512+ exists ( NameBinding b |
513+ b = getStaticBindingTargetFromRef ( this .getCallee ( ) ) and
504514 result .getNameNode ( ) = b
505515 )
506516 }
@@ -659,10 +669,20 @@ module Input3 implements InputSig3 {
659669 result = getQualifierTypeMention ( invocation )
660670 }
661671
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 )
672+ private predicate constructionReceiver (
673+ Invocation i , Callable constructor , Expr receiver , TypePath enumPrefixPath
674+ ) {
675+ exists ( ConstructorDeclaration cd |
676+ constructor = i .getTargetImpl ( _) and
677+ cd = constructor .asCallable ( ) and
678+ receiver = i .getArgument ( 0 )
679+ |
680+ enumPrefixPath =
681+ TypePath:: singleton ( TParentTypeParameterType ( cd .( EnumCaseConstructor ) .getEnumCaseClass ( ) ) )
682+ or
683+ not cd instanceof EnumCaseConstructor and
684+ enumPrefixPath .isEmpty ( )
685+ )
666686 }
667687
668688 /**
@@ -696,11 +716,15 @@ module Input3 implements InputSig3 {
696716 M3:: ContextualTyping:: ContextualReturnType< ContextualConstructorReturnTypeInput > ;
697717
698718 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 )
719+ exists (
720+ Callable constructor , Expr receiver , TypePath enumPrefixPath ,
721+ ClassLikeDeclarationType receiverType , TypePath path0
722+ |
723+ constructionReceiver ( i , constructor , receiver , enumPrefixPath ) and
724+ receiverType = inferType ( receiver ) and
725+ path = path0 .stripPrefix ( enumPrefixPath )
702726 |
703- ContextualConstructorReturnType:: needsContextualTyping ( i , path ) and
727+ ContextualConstructorReturnType:: needsContextualTyping ( i , path0 ) and
704728 receiverType = constructor .getDeclaringType ( ) .getType ( )
705729 or
706730 // inherited constructor
@@ -710,18 +734,19 @@ module Input3 implements InputSig3 {
710734 |
711735 declType = constructor .getDeclaringType ( ) .getType ( ) and
712736 BaseTypes:: rootTypesSatisfaction ( receiverType , declType , abs , _, constraint ) and
713- path = TypePath:: singleton ( tp )
737+ tp =
738+ getClassLikeDeclarationTypeMention ( receiverType .getClassLikeDeclaration ( ) )
739+ .getTypeAt ( path0 )
714740 |
715741 // `A<T> : B<T>`
716- exists ( TypePath path0 |
717- BaseTypes:: conditionSatisfiesConstraintTypeAt ( abs , _, constraint , path0 , tp ) and
718- ContextualConstructorReturnType:: needsContextualTyping ( i , path0 )
742+ exists ( TypePath path1 |
743+ BaseTypes:: conditionSatisfiesConstraintTypeAt ( abs , _, constraint , path1 , tp ) and
744+ ContextualConstructorReturnType:: needsContextualTyping ( i , path1 )
719745 )
720746 or
721747 // `A<T> : B`
722- tp = receiverType .getATypeParameter ( ) and
723748 not BaseTypes:: conditionSatisfiesConstraintTypeAt ( abs , _, constraint , _, tp ) and
724- not exists ( Type t | t = i .getTypeQualifier ( path ) and not t instanceof PseudoType )
749+ not exists ( Type t | t = i .getTypeQualifier ( path0 ) and not t instanceof PseudoType )
725750 )
726751 )
727752 }
@@ -734,8 +759,7 @@ module Input3 implements InputSig3 {
734759 * as well as calls receivers, `self.init(0)` or `super.init(0)`.
735760 */
736761 predicate step ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
737- constructionReceiver ( n2 , _, n1 ) and
738- prefix1 .isEmpty ( ) and
762+ constructionReceiver ( n2 , _, n1 , prefix1 ) and
739763 prefix2 .isEmpty ( )
740764 }
741765
0 commit comments