Fix compilation exception where overload ambiguity should be

#KT-16246 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-09-05 13:40:50 +03:00
parent ec512d1c8a
commit 6d4bb229ac
6 changed files with 47 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ fun <D : CallableDescriptor> ResolvedCall<D>.usesDefaultArguments(): Boolean {
fun <C: ResolutionContext<C>> Call.hasUnresolvedArguments(context: ResolutionContext<C>): Boolean {
val arguments = valueArguments.map { it.getArgumentExpression() }
return arguments.any (fun (argument: KtExpression?): Boolean {
if (argument == null || ArgumentTypeResolver.isFunctionLiteralArgument(argument, context)) return false
if (argument == null || ArgumentTypeResolver.isFunctionLiteralOrCallableReference(argument, context)) return false
val resolvedCall = argument.getResolvedCall(context.trace.bindingContext) as MutableResolvedCall<*>?
if (resolvedCall != null && !resolvedCall.hasInferredReturnType()) return false
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.reflect.KCallable
class Foo {
fun <T> installRoute(handler: T) where T : (String) -> Any?, T : KCallable<*> {
}
fun <T> installRoute(handler: T) where T : () -> Any?, T : KCallable<*> {
}
fun foo() {
<!OVERLOAD_RESOLUTION_AMBIGUITY!>installRoute<!><Any>(::route)
}
}
fun route(s: String): Any? = null
@@ -0,0 +1,13 @@
package
public fun route(/*0*/ s: kotlin.String): kotlin.Any?
public final class Foo {
public constructor Foo()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun </*0*/ T : () -> kotlin.Any?> installRoute(/*0*/ handler: T): kotlin.Unit where T : kotlin.reflect.KCallable<*>
public final fun </*0*/ T : (kotlin.String) -> kotlin.Any?> installRoute(/*0*/ handler: T): kotlin.Unit where T : kotlin.reflect.KCallable<*>
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -20,7 +20,7 @@ val x1 = fn1(1, ::foo, ::foo)
val x2 = fn1(1, ::foo, ::bar)
val x3 = fn2(::bar, ::foo)
val x4 = fn2(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::bar)
val x5 = fn2(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
val x4 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::bar)
val x5 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>fn2<!>(::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>, ::<!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>)
val x6 = fn3(1, ::qux)
@@ -2580,6 +2580,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("intersectionTypeOverloadWithWrongParameter.kt")
public void testIntersectionTypeOverloadWithWrongParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/intersectionTypeOverloadWithWrongParameter.kt");
doTest(fileName);
}
@TestMetadata("kt10036.kt")
public void testKt10036() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.kt");
@@ -2580,6 +2580,12 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
doTest(fileName);
}
@TestMetadata("intersectionTypeOverloadWithWrongParameter.kt")
public void testIntersectionTypeOverloadWithWrongParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/intersectionTypeOverloadWithWrongParameter.kt");
doTest(fileName);
}
@TestMetadata("kt10036.kt")
public void testKt10036() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/resolve/kt10036.kt");