K2: Avoid inference diagnostics when arguments are already error typed
For example, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER
It became especially relevant after 0e84bf2053
that together with later commits bring a lot of unnecessary
NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER diagnostic
This commit is contained in:
committed by
Space Team
parent
564b40f05d
commit
fe5adab652
+1
-1
@@ -2,5 +2,5 @@ FILE: functionWithImplicitType.kt
|
||||
public final [BODY_RESOLVE] fun <[BODY_RESOLVE] T> checkSubtype([BODY_RESOLVE] t: R|T|): R|T| {
|
||||
^checkSubtype R|<local>/t|
|
||||
}
|
||||
public final [BODY_RESOLVE] val ab: R|kotlin/collections/List<kotlin/Int>?| = R|/checkSubtype|<R|kotlin/collections/List<kotlin/Int>?|>(<Unresolved name: Collections>#.<Unresolved name: emptyList>#<R|kotlin/Int|>())
|
||||
public final [BODY_RESOLVE] val ab: R|kotlin/collections/List<kotlin/Int>?| = R|/checkSubtype<Inapplicable(INAPPLICABLE): /checkSubtype>#|<R|kotlin/collections/List<kotlin/Int>?|>(<Unresolved name: Collections>#.<Unresolved name: emptyList>#<R|kotlin/Int|>())
|
||||
public [BODY_RESOLVE] get(): R|kotlin/collections/List<kotlin/Int>?|
|
||||
|
||||
+4
@@ -225,6 +225,10 @@ private fun mapInapplicableCandidateError(
|
||||
)
|
||||
}
|
||||
|
||||
// We don't report anything here, because there are already some errors inside the call or declaration
|
||||
// And the errors should be reported there
|
||||
is ErrorTypeInArguments -> null
|
||||
|
||||
is MultipleContextReceiversApplicableForExtensionReceivers ->
|
||||
FirErrors.AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER.createOn(qualifiedAccessSource ?: source)
|
||||
|
||||
|
||||
@@ -352,13 +352,12 @@ private fun checkApplicabilityForArgumentType(
|
||||
// todo run this approximation only once for call
|
||||
val argumentType = captureFromTypeParameterUpperBoundIfNeeded(argumentTypeBeforeCapturing, expectedType, context.session)
|
||||
|
||||
fun subtypeError(actualExpectedType: ConeKotlinType): ResolutionDiagnostic? {
|
||||
fun subtypeError(actualExpectedType: ConeKotlinType): ResolutionDiagnostic {
|
||||
if (argument.isNullLiteral && actualExpectedType.nullability == ConeNullability.NOT_NULL) {
|
||||
return NullForNotNullType(argument)
|
||||
}
|
||||
|
||||
fun tryGetConeTypeThatCompatibleWithKtType(type: ConeKotlinType): ConeKotlinType? {
|
||||
if (type is ConeErrorType) return null
|
||||
fun tryGetConeTypeThatCompatibleWithKtType(type: ConeKotlinType): ConeKotlinType {
|
||||
if (type is ConeTypeVariableType) {
|
||||
val lookupTag = type.lookupTag
|
||||
|
||||
@@ -380,8 +379,10 @@ private fun checkApplicabilityForArgumentType(
|
||||
return type
|
||||
}
|
||||
|
||||
val preparedExpectedType = tryGetConeTypeThatCompatibleWithKtType(actualExpectedType) ?: return null
|
||||
val preparedActualType = tryGetConeTypeThatCompatibleWithKtType(argumentType) ?: return null
|
||||
if (argumentType is ConeErrorType || actualExpectedType is ConeErrorType) return ErrorTypeInArguments
|
||||
|
||||
val preparedExpectedType = tryGetConeTypeThatCompatibleWithKtType(actualExpectedType)
|
||||
val preparedActualType = tryGetConeTypeThatCompatibleWithKtType(argumentType)
|
||||
return ArgumentTypeMismatch(
|
||||
preparedExpectedType,
|
||||
preparedActualType,
|
||||
@@ -419,7 +420,7 @@ private fun checkApplicabilityForArgumentType(
|
||||
}
|
||||
|
||||
if (!isReceiver) {
|
||||
sink.reportDiagnosticIfNotNull(subtypeError(expectedType))
|
||||
sink.reportDiagnostic(subtypeError(expectedType))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -78,6 +78,8 @@ class NameForAmbiguousParameter(
|
||||
|
||||
object InapplicableCandidate : ResolutionDiagnostic(INAPPLICABLE)
|
||||
|
||||
object ErrorTypeInArguments : ResolutionDiagnostic(INAPPLICABLE)
|
||||
|
||||
object HiddenCandidate : ResolutionDiagnostic(HIDDEN)
|
||||
|
||||
object VisibilityError : ResolutionDiagnostic(K2_VISIBILITY_ERROR)
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
var a: Int by A()
|
||||
var a1 by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A()<!>
|
||||
var a1 by <!DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>A()<!>
|
||||
|
||||
var b: Int by B()
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class B {
|
||||
val c by <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>Delegate<!>(<!UNRESOLVED_REFERENCE!>ag<!>)
|
||||
val c by Delegate(<!UNRESOLVED_REFERENCE!>ag<!>)
|
||||
}
|
||||
|
||||
class Delegate<T: Any>(val init: T) {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ fun test() {
|
||||
A.<!OPT_IN_USAGE_ERROR!>entries<!>
|
||||
A.Companion.entries
|
||||
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>(A) {
|
||||
with(A) {
|
||||
entries
|
||||
this.entries
|
||||
<!UNRESOLVED_REFERENCE!>values<!>() // to be sure that we don't resolve into synthetic 'values'
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ fun test() {
|
||||
A.<!OPT_IN_USAGE_ERROR!>entries<!>
|
||||
A.Companion.entries
|
||||
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>(A) {
|
||||
with(A) {
|
||||
entries
|
||||
this.entries
|
||||
<!UNRESOLVED_REFERENCE!>values<!>() // to be sure that we don't resolve into synthetic 'values'
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface JPAEntityClass<D> {
|
||||
fun <T> T.findByName(s: String): D {null!!}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
companion object : JPAEntityClass<Foo>
|
||||
}
|
||||
|
||||
fun main() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>("", {
|
||||
Foo.<!UNRESOLVED_REFERENCE!>findByName<!>("")
|
||||
})
|
||||
with(Foo) {
|
||||
findByName("")
|
||||
}
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface JPAEntityClass<D> {
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ fun testUnit() {
|
||||
fun testParameter() {
|
||||
takeFnToParameter { }
|
||||
takeFnToParameter { Unit }
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>takeFnToParameter<!> { <!UNRESOLVED_REFERENCE!>unresolved<!>() }
|
||||
takeFnToParameter { <!UNRESOLVED_REFERENCE!>unresolved<!>() }
|
||||
takeFnToParameter { if (true) <!UNRESOLVED_REFERENCE!>unresolved<!>() }
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>takeFnToParameter<!> {
|
||||
if (true) <!UNRESOLVED_REFERENCE!>unresolved<!>() else <!UNRESOLVED_REFERENCE!>unresolved<!>()
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ fun main() {
|
||||
val number: Int = 5 // doesn't work
|
||||
// val number: Long = 5 // works
|
||||
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!> (WrapperFunctions()) {
|
||||
with (WrapperFunctions()) {
|
||||
wrapper <!NONE_APPLICABLE!>greaterEq<!> number
|
||||
}
|
||||
}
|
||||
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
package n
|
||||
|
||||
fun <T> foo(t: T, t1: T) {}
|
||||
|
||||
fun test() {
|
||||
//no type inference error
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>(<!UNRESOLVED_REFERENCE!>aaab<!>, <!UNRESOLVED_REFERENCE!>bbb<!>)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
package n
|
||||
|
||||
fun <T> foo(t: T, t1: T) {}
|
||||
|
||||
Vendored
+1
-1
@@ -26,7 +26,7 @@ fun testParam() {
|
||||
}
|
||||
|
||||
fun testParamCall() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>callParam<!> {
|
||||
callParam {
|
||||
param -> <!UNRESOLVED_REFERENCE!>param<!>()
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -37,7 +37,7 @@ fun testStarProjection() = BiParam(
|
||||
intersect(First, Second),
|
||||
makeStarProjection()
|
||||
)
|
||||
fun testErrorType() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>BiParam<!>(
|
||||
fun testErrorType() = BiParam(
|
||||
intersect(First, Second),
|
||||
<!UNRESOLVED_REFERENCE!>unresolved<!>
|
||||
)
|
||||
|
||||
+4
-4
@@ -12,7 +12,7 @@ fun insideJob1() = doTheJob1()
|
||||
suspend fun insideJob2() = doTheJob2()
|
||||
suspend fun insideJob3() = doTheJob3()
|
||||
|
||||
fun doTheJob0() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>simpleAsync0<!> { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>insideJob0()<!> }
|
||||
fun doTheJob1() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>simpleAsync1<!> { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>insideJob1()<!> }
|
||||
suspend fun doTheJob2() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>simpleAsync2<!> { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!><!NON_LOCAL_SUSPENSION_POINT!>insideJob2<!>()<!> }
|
||||
suspend fun doTheJob3() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>simpleAsync3<!> { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>insideJob3()<!> }
|
||||
fun doTheJob0() = simpleAsync0 { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>insideJob0()<!> }
|
||||
fun doTheJob1() = simpleAsync1 { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>insideJob1()<!> }
|
||||
suspend fun doTheJob2() = simpleAsync2 { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!><!NON_LOCAL_SUSPENSION_POINT!>insideJob2<!>()<!> }
|
||||
suspend fun doTheJob3() = simpleAsync3 { <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>insideJob3()<!> }
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ fun foo() {
|
||||
fun bar1() = bar1()
|
||||
|
||||
fun bar2() = 1 <!OVERLOAD_RESOLUTION_AMBIGUITY!>+<!> bar2()
|
||||
fun bar3() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>id<!>(bar3())
|
||||
fun bar3() = id(bar3())
|
||||
}
|
||||
|
||||
fun <T> id(x: T) = x
|
||||
|
||||
@@ -8,5 +8,5 @@ fun <T> _arrayList(vararg values: T) : List<T> = throw Exception()
|
||||
class _Pair<A>(val a: A)
|
||||
|
||||
fun test() {
|
||||
_arrayList(_Pair(1)).<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>_sortBy<!> { it -> <!UNRESOLVED_REFERENCE!>xxx<!> }
|
||||
_arrayList(_Pair(1))._sortBy { it -> <!UNRESOLVED_REFERENCE!>xxx<!> }
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {}
|
||||
class C : Closeable {}
|
||||
|
||||
public inline fun <T: Closeable, R> T.use1(block: (T)-> R) : R {
|
||||
return block(this)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
C().<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use1<!> {
|
||||
w -> // ERROR here
|
||||
<!UNRESOLVED_REFERENCE!>x<!>
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {
|
||||
fun close() {}
|
||||
}
|
||||
|
||||
class C : Closeable
|
||||
|
||||
public inline fun <T: Closeable, R> T.use(block: (t: T)-> R) : R {
|
||||
return block(this)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
C().<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use<!> {
|
||||
it.close()
|
||||
<!UNRESOLVED_REFERENCE!>x<!>
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
package a
|
||||
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {
|
||||
fun close() {}
|
||||
}
|
||||
|
||||
class C : Closeable
|
||||
|
||||
public inline fun <T: Closeable, R> use(t: T, block: T.(T)-> R) : R {
|
||||
return t.block(t)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use<!>(C()) {
|
||||
this.close()
|
||||
it.close()
|
||||
<!UNRESOLVED_REFERENCE!>xx<!>
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {
|
||||
fun close() {}
|
||||
}
|
||||
|
||||
class C : Closeable
|
||||
|
||||
public inline fun <T: Closeable, R> T.use(block: T.()-> R) : R {
|
||||
return this.block()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
C().<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use<!> {
|
||||
this.close()
|
||||
<!UNRESOLVED_REFERENCE!>x<!>
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ fun test() {
|
||||
id(<!UNRESOLVED_REFERENCE!>unresolved<!>)
|
||||
|
||||
when {
|
||||
true -> <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>id<!>(<!UNRESOLVED_REFERENCE!>unresolved<!>)
|
||||
true -> id(<!UNRESOLVED_REFERENCE!>unresolved<!>)
|
||||
}
|
||||
id(<!UNRESOLVED_REFERENCE!>unresolved<!>) ?: id(<!UNRESOLVED_REFERENCE!>unresolved<!>)
|
||||
}
|
||||
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
|
||||
package a
|
||||
|
||||
interface Closeable {}
|
||||
class C : Closeable {}
|
||||
|
||||
fun <T: Closeable, R> T.foo(block: (T)-> R) = block
|
||||
|
||||
fun <T: Closeable, R> T.foo(block: (T, T)-> R) = block
|
||||
|
||||
fun main() {
|
||||
C().<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!> { // no ambiguity here
|
||||
www ->
|
||||
<!UNRESOLVED_REFERENCE!>xs<!>
|
||||
}
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
package a
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ fun <K> id2(x: K, s: String): K = x
|
||||
fun <K> ret(s: String): K = TODO()
|
||||
|
||||
fun test() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>id2<!>(<!UNRESOLVED_REFERENCE!>unresolved<!>, "foo")
|
||||
id2(<!UNRESOLVED_REFERENCE!>unresolved<!>, "foo")
|
||||
id2(<!UNRESOLVED_REFERENCE!>unresolved<!>, <!ARGUMENT_TYPE_MISMATCH!>42<!>)
|
||||
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>ret<!>("foo")
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ class A {
|
||||
val a get() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>b<!>
|
||||
val b get() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>a<!>
|
||||
|
||||
val z1 get() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>id<!>(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>z1<!>)
|
||||
val z2 get() = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>l<!>(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>z2<!>)
|
||||
val z1 get() = id(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>z1<!>)
|
||||
val z2 get() = l(<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>z2<!>)
|
||||
|
||||
val u get() = <!UNRESOLVED_REFERENCE!>field<!>
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// !RENDER_DIAGNOSTICS_FULL_TEXT
|
||||
|
||||
fun Int.with() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>("") {
|
||||
with("") {
|
||||
this@with.<!UNRESOLVED_REFERENCE!>inc<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun Int.bar() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>("") bar@{
|
||||
with("") bar@{
|
||||
this@bar.<!UNRESOLVED_REFERENCE!>inc<!>()
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@ fun foo(f: with.() -> Unit) {}
|
||||
|
||||
class with {
|
||||
fun foo() {
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>("") {
|
||||
with("") {
|
||||
this@with.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
}
|
||||
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>("") with@{
|
||||
with("") with@{
|
||||
this@with.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user