overload resolution: apply site substitution before potential compatibility check (IDEA-150807)

This commit is contained in:
Anna Kozlova
2016-01-25 18:52:15 +03:00
parent ec2c691cbf
commit 883f7f3f39
3 changed files with 38 additions and 1 deletions
@@ -196,7 +196,7 @@ public class MethodCandidateInfo extends CandidateInfo{
formalParameterType = ((PsiEllipsisType)formalParameterType).getComponentType();
}
if (!isPotentialCompatible(expression, formalParameterType, method)) {
if (!isPotentialCompatible(expression, getSiteSubstitutor().substitute(formalParameterType), method)) {
return false;
}
}
@@ -0,0 +1,33 @@
import java.util.function.Function;
class Test {
static class MyMap<V>
{
V put( char[] key, V value )
{
return null;
}
V put( String key, V value )
{
return null;
}
}
static final MyMap<Test.F> s_funcMap = new MyMap<>();
interface F extends Function<Thread,Number> { }
static
{
// without casts
s_funcMap.put( "ID", Thread::getId );
s_funcMap.put( "ID", thread -> thread.getId() + 1 );
s_funcMap.put( "ID", thread -> { return thread.getId() + 1; } );
// with casts
s_funcMap.put( "ID", (Test.F) Thread::getId );
s_funcMap.put( "ID", (Test.F) thread -> thread.getId() + 1 );
s_funcMap.put( "ID", (Test.F) thread -> { return thread.getId() + 1; } );
}
}
@@ -188,6 +188,10 @@ public class OverloadResolutionTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testPotentiallyCompatibleShouldCheckAgainstSubstitutedWithSiteSubstitutor() throws Exception {
doTest(false);
}
private void doTest() {
doTest(true);
}