diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java index 3a4e80bda6dc..9b9cfa6b31d4 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceIncorporationPhase.java @@ -126,6 +126,21 @@ public class InferenceIncorporationPhase { LOG.assertTrue(gClass != null); final InferenceVariable[] parameters = capture.first; PsiType[] typeArgs = right.getParameters(); + PsiSubstitutor restSubst = PsiSubstitutor.EMPTY; + if (Registry.is("javac.fresh.variables.for.captured.wildcards.only")) { + List args = new ArrayList(); + PsiTypeParameter[] typeParameters = gClass.getTypeParameters(); + for (int i = 0; i < typeArgs.length; i++) { + PsiType arg = typeArgs[i]; + if (arg instanceof PsiWildcardType) { + args.add(arg); + } + else { + restSubst = restSubst.put(typeParameters[i], arg); + } + } + typeArgs = args.toArray(PsiType.EMPTY_ARRAY); + } if (parameters.length != typeArgs.length) continue; for (int i = 0; i < typeArgs.length; i++) { final PsiType aType = typeArgs[i]; @@ -155,6 +170,8 @@ public class InferenceIncorporationPhase { } } + glb = restSubst.substitute(glb); + if (!((PsiWildcardType)aType).isBounded()) { for (PsiType upperBound : upperBounds) {