method refs: fix variable initializing order (IDEA-132445)

This commit is contained in:
Anna Kozlova
2014-11-06 19:11:29 +01:00
parent 51262ecf74
commit bba30278f9
3 changed files with 28 additions and 3 deletions
@@ -169,13 +169,13 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
}
LOG.assertTrue(referencedMethodReturnType != null, method);
session.initBounds(myExpression, method.getTypeParameters());
if (!PsiTreeUtil.isContextAncestor(containingClass, myExpression, false) ||
if (!PsiTreeUtil.isContextAncestor(containingClass, myExpression, false) ||
PsiUtil.getEnclosingStaticElement(myExpression, containingClass) != null) {
session.initBounds(myExpression, containingClass.getTypeParameters());
}
session.initBounds(myExpression, method.getTypeParameters());
//if i) the method reference elides NonWildTypeArguments,
// ii) the compile-time declaration is a generic method, and
// iii) the return type of the compile-time declaration mentions at least one of the method's type parameters;
@@ -0,0 +1,21 @@
import java.util.function.Function;
interface Repository<T> {
<S extends T> S save(S s);
}
interface Builder<T> {
T build();
default <D> Builder<D> map(Function<T, D> fx) {
return () -> fx.apply(this.build());
}
}
class Usage {
void test(Repository<String> repository, Builder<String> sample) {
sample.map(repository::save).build();
sample.map((s) -> repository.save(s)).build();
}
}
@@ -318,6 +318,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testTypeParametersInitOrder() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}