new inference: captures should stay closed inside nested calls

This commit is contained in:
Anna Kozlova
2014-02-28 20:07:08 +01:00
parent e683dc8fc1
commit d8b3e5c7fd
4 changed files with 28 additions and 1 deletions
@@ -493,6 +493,13 @@ public class PsiImplUtil {
return PsiUtil.captureToplevelWildcards(type, expression);
}
final PsiElement parent = toplevel.getParent();
if (parent instanceof PsiExpressionList &&
PsiUtil.isLanguageLevel8OrHigher(parent) &&
parent.getParent() instanceof PsiCallExpression) {
return PsiUtil.captureToplevelWildcards(type, expression);
}
final PsiType normalized = doNormalizeWildcardByPosition(type, expression, toplevel);
LOG.assertTrue(normalized.isValid(), type);
if (normalized instanceof PsiClassType && !PsiUtil.isAccessedForWriting(toplevel)) {
@@ -142,7 +142,7 @@ class S1 {
}
void bar(List<? extends S1> k) {
f<error descr="'f(java.util.List<capture<? extends S1>>, capture<? extends S1>)' in 'S1' cannot be applied to '(java.util.List<capture<? extends S1>>, S1)'">(k, k.get(0))</error>;
f<error descr="'f(java.util.List<capture<? extends S1>>, capture<? extends S1>)' in 'S1' cannot be applied to '(java.util.List<capture<? extends S1>>, capture<? extends S1>)'">(k, k.get(0))</error>;
}
}
@@ -0,0 +1,16 @@
class Test {
class Foo<K> {}
void test(Foo<? extends String> p) {
foo(bar(p)) ;
}
<T> T bar(Foo<T> p) {
return null;
}
<K> K foo(K p) {
return null;
}
}
@@ -160,6 +160,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testLiftedCaptureToOuterCall() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}