Use more specific status to report diagnostics
#KT-12737 Fixed
This commit is contained in:
+1
@@ -469,6 +469,7 @@ internal fun createPreviousResolveError(status: ResolutionStatus): PreviousResol
|
|||||||
val level = when (status) {
|
val level = when (status) {
|
||||||
ResolutionStatus.SUCCESS, ResolutionStatus.INCOMPLETE_TYPE_INFERENCE -> return null
|
ResolutionStatus.SUCCESS, ResolutionStatus.INCOMPLETE_TYPE_INFERENCE -> return null
|
||||||
ResolutionStatus.UNSAFE_CALL_ERROR -> ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR
|
ResolutionStatus.UNSAFE_CALL_ERROR -> ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR
|
||||||
|
ResolutionStatus.ARGUMENTS_MAPPING_ERROR -> ResolutionCandidateApplicability.INAPPLICABLE_ARGUMENTS_MAPPING_ERROR
|
||||||
ResolutionStatus.RECEIVER_TYPE_ERROR -> ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
ResolutionStatus.RECEIVER_TYPE_ERROR -> ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
||||||
else -> ResolutionCandidateApplicability.INAPPLICABLE
|
else -> ResolutionCandidateApplicability.INAPPLICABLE
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -71,7 +71,8 @@ enum class ResolutionCandidateApplicability {
|
|||||||
MAY_THROW_RUNTIME_ERROR, // unsafe call or unstable smart cast
|
MAY_THROW_RUNTIME_ERROR, // unsafe call or unstable smart cast
|
||||||
RUNTIME_ERROR, // problems with visibility
|
RUNTIME_ERROR, // problems with visibility
|
||||||
IMPOSSIBLE_TO_GENERATE, // access to outer class from nested
|
IMPOSSIBLE_TO_GENERATE, // access to outer class from nested
|
||||||
INAPPLICABLE, // arguments not matched
|
INAPPLICABLE, // arguments have wrong types
|
||||||
|
INAPPLICABLE_ARGUMENTS_MAPPING_ERROR, // arguments not mapped to parameters (i.e. different size of arguments and parameters)
|
||||||
INAPPLICABLE_WRONG_RECEIVER, // receiver not matched
|
INAPPLICABLE_WRONG_RECEIVER, // receiver not matched
|
||||||
HIDDEN, // removed from resolve
|
HIDDEN, // removed from resolve
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo
|
||||||
|
|
||||||
|
private val INAPPLICABLE_STATUSES = setOf(
|
||||||
|
ResolutionCandidateApplicability.INAPPLICABLE,
|
||||||
|
ResolutionCandidateApplicability.INAPPLICABLE_ARGUMENTS_MAPPING_ERROR,
|
||||||
|
ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER)
|
||||||
|
|
||||||
val ResolutionCandidateApplicability.isSuccess: Boolean
|
val ResolutionCandidateApplicability.isSuccess: Boolean
|
||||||
get() = this <= ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY
|
get() = this <= ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY
|
||||||
|
|
||||||
@@ -30,7 +35,7 @@ val CandidateWithBoundDispatchReceiver.requiresExtensionReceiver: Boolean
|
|||||||
get() = descriptor.extensionReceiverParameter != null
|
get() = descriptor.extensionReceiverParameter != null
|
||||||
|
|
||||||
val ResolutionCandidateApplicability.isInapplicable: Boolean
|
val ResolutionCandidateApplicability.isInapplicable: Boolean
|
||||||
get() = this == ResolutionCandidateApplicability.INAPPLICABLE || this == ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
get() = this in INAPPLICABLE_STATUSES
|
||||||
|
|
||||||
internal class CandidateWithBoundDispatchReceiverImpl(
|
internal class CandidateWithBoundDispatchReceiverImpl(
|
||||||
override val dispatchReceiver: ReceiverValueWithSmartCastInfo?,
|
override val dispatchReceiver: ReceiverValueWithSmartCastInfo?,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class C : T {
|
|||||||
super.foo() // OK
|
super.foo() // OK
|
||||||
<!SUPER_CANT_BE_EXTENSION_RECEIVER!>super<!>.bar() // Error
|
<!SUPER_CANT_BE_EXTENSION_RECEIVER!>super<!>.bar() // Error
|
||||||
super.buzz() // OK, resolved to a member
|
super.buzz() // OK, resolved to a member
|
||||||
super.buzz1(<!NO_VALUE_FOR_PARAMETER!>)<!> // Resolved to a member, but error: no parameter passed where required
|
<!SUPER_CANT_BE_EXTENSION_RECEIVER!>super<!>.buzz1() // Resolved to an extension
|
||||||
|
super.buzz1(<!TYPE_MISMATCH!>""<!>) // Resolved to a member
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun Runnable.test(f: Runnable.(Int) -> Unit) {
|
||||||
|
f(<!TYPE_MISMATCH!>""<!>)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test(f: Runnable.(Int) -> Unit, runnable: Runnable) {
|
||||||
|
with (runnable) {
|
||||||
|
f(<!TYPE_MISMATCH!>""<!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Int.test(f: String.(Int) -> Unit) {
|
||||||
|
f("", 0)
|
||||||
|
f(""<!NO_VALUE_FOR_PARAMETER!>)<!>
|
||||||
|
with("") {
|
||||||
|
f(0)
|
||||||
|
f(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>0.0<!>)
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test(/*0*/ f: java.lang.Runnable.(kotlin.Int) -> kotlin.Unit, /*1*/ runnable: java.lang.Runnable): kotlin.Unit
|
||||||
|
public fun java.lang.Runnable.test(/*0*/ f: java.lang.Runnable.(kotlin.Int) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun kotlin.Int.test(/*0*/ f: kotlin.String.(kotlin.Int) -> kotlin.Unit): kotlin.Unit
|
||||||
@@ -17,5 +17,5 @@ val test2 = WI(<!TOO_MANY_ARGUMENTS!>null<!>)
|
|||||||
|
|
||||||
val test3 = CWI()
|
val test3 = CWI()
|
||||||
val test4 = CWI("")
|
val test4 = CWI("")
|
||||||
val test5 = CWI(<!TOO_MANY_ARGUMENTS!>null<!>)
|
val test5 = CWI(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||||
val test5a = ClassWithCompanionObjectWithInvoke(<!TOO_MANY_ARGUMENTS!>null<!>)
|
val test5a = ClassWithCompanionObjectWithInvoke(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@ public val test1: ObjectWithInvoke
|
|||||||
public val test2: ObjectWithInvoke
|
public val test2: ObjectWithInvoke
|
||||||
public val test3: CWI /* = ClassWithCompanionObjectWithInvoke */
|
public val test3: CWI /* = ClassWithCompanionObjectWithInvoke */
|
||||||
public val test4: kotlin.Any
|
public val test4: kotlin.Any
|
||||||
public val test5: CWI /* = ClassWithCompanionObjectWithInvoke */
|
public val test5: kotlin.Any
|
||||||
public val test5a: ClassWithCompanionObjectWithInvoke
|
public val test5a: kotlin.Any
|
||||||
|
|
||||||
public final class ClassWithCompanionObjectWithInvoke {
|
public final class ClassWithCompanionObjectWithInvoke {
|
||||||
public constructor ClassWithCompanionObjectWithInvoke()
|
public constructor ClassWithCompanionObjectWithInvoke()
|
||||||
|
|||||||
@@ -10931,6 +10931,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentExtensionFunction.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("wrongArgumentPassedToLocalExtensionFunction.kt")
|
||||||
|
public void testWrongArgumentPassedToLocalExtensionFunction() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/reportingImprovements/wrongArgumentPassedToLocalExtensionFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/inference/substitutions")
|
@TestMetadata("compiler/testData/diagnostics/tests/inference/substitutions")
|
||||||
|
|||||||
+21
-1
@@ -1,5 +1,5 @@
|
|||||||
// FILE: first.before.kt
|
// FILE: first.before.kt
|
||||||
// "Import" "false"
|
// "Import" "true"
|
||||||
// ERROR: Too many arguments for public final fun foo(): Unit defined in main.X
|
// ERROR: Too many arguments for public final fun foo(): Unit defined in main.X
|
||||||
// ACTION: Add parameter to function 'foo'
|
// ACTION: Add parameter to function 'foo'
|
||||||
// ACTION: Create extension function 'X.foo'
|
// ACTION: Create extension function 'X.foo'
|
||||||
@@ -23,3 +23,23 @@ import main.X
|
|||||||
|
|
||||||
fun X.foo(p: String) {
|
fun X.foo(p: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FILE: first.after.kt
|
||||||
|
// "Import" "true"
|
||||||
|
// ERROR: Too many arguments for public final fun foo(): Unit defined in main.X
|
||||||
|
// ACTION: Add parameter to function 'foo'
|
||||||
|
// ACTION: Create extension function 'X.foo'
|
||||||
|
// ACTION: Create member function 'X.foo'
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import other.foo
|
||||||
|
|
||||||
|
class X {
|
||||||
|
fun foo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
fun f() {
|
||||||
|
this.foo(<caret>1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
// ERROR: Too many arguments for public constructor String() defined in kotlin.String
|
// ERROR: Type mismatch: inferred type is String but Charset was expected
|
||||||
// ERROR: Too many arguments for public constructor String() defined in kotlin.String
|
// ERROR: Type mismatch: inferred type is String but Charset was expected
|
||||||
// ERROR: Too many arguments for public constructor String() defined in kotlin.String
|
|
||||||
// ERROR: Too many arguments for public constructor String() defined in kotlin.String
|
|
||||||
// ERROR: Too many arguments for public constructor String() defined in kotlin.String
|
|
||||||
// ERROR: Too many arguments for public constructor String() defined in kotlin.String
|
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user