K2: report only warning on lambda parameters with missing dependencies

During the fix of KT-62525, we've forbidden to use lambda parameters
with inaccessible types at all. After it, some impact was noticed,
so we decided to forbid them only in case it's necessary
(the case when associated types have type arguments, see KT-62525
description), and to deprecate them in other cases.

#KT-64266 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-12-19 14:51:55 +01:00
committed by Space Team
parent 44aa2d86d3
commit c322644860
22 changed files with 172 additions and 27 deletions
@@ -1,15 +1,15 @@
// -- Module: <m1> --
// -- Module: <m2> --
/m2.kt:13:9: warning: parameter 'f' is never used
/m2.kt:14:9: warning: parameter 'f' is never used
fun foo(f: (Some, String) -> Unit) {}
^
/m2.kt:14:9: warning: parameter 'f' is never used
/m2.kt:15:9: warning: parameter 'f' is never used
fun bar(f: (Some) -> Unit) {}
^
// -- Module: <m3> --
/m3.kt:23:17: error: unresolved reference: Some
/m3.kt:24:17: error: unresolved reference: Some
foo { some: Some, _ -> }
^
@@ -1,23 +1,23 @@
/m3.kt:(72,73): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(73,74): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(92,96): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(93,97): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(117,121): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(118,122): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(128,132): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(129,133): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(162,166): error: Unresolved reference 'Some'.
/m3.kt:(163,167): error: Unresolved reference 'Some'.
/m3.kt:(184,187): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(185,188): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(198,199): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(199,200): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(215,217): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(216,218): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(231,248): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(232,249): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(233,235): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(234,236): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(259,263): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(260,264): warning: Class 'Some' of the lambda parameter is inaccessible. While it may work, this case is dangerous and may be forbidden soon. Consider adding a necessary dependency to your module classpath.
/m3.kt:(267,271): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
/m3.kt:(268,272): error: Cannot access class 'Some'. Check your module classpath for missing or conflicting dependencies.
@@ -1,5 +1,6 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
// LANGUAGE: -ForbidLambdaParameterWithMissingDependencyType
// ISSUE: KT-64266
// MODULE: m1
@@ -17,14 +18,14 @@ fun bar(f: (Some) -> Unit) {}
// FILE: m3.kt
fun test() {
foo { <!MISSING_DEPENDENCY_CLASS!>_<!>, _ -> }
foo { <!MISSING_DEPENDENCY_CLASS!>some<!>, str -> }
foo { <!MISSING_DEPENDENCY_CLASS!>some<!>, _ -> <!MISSING_DEPENDENCY_CLASS!>some<!>.toString() }
foo { <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>_<!>, _ -> }
foo { <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>some<!>, str -> }
foo { <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>some<!>, _ -> <!MISSING_DEPENDENCY_CLASS!>some<!>.toString() }
foo { some: <!UNRESOLVED_REFERENCE!>Some<!>, _ -> }
bar <!MISSING_DEPENDENCY_CLASS!>{ }<!>
bar { <!MISSING_DEPENDENCY_CLASS!>_<!> -> }
bar { <!MISSING_DEPENDENCY_CLASS!>it<!> -> }
bar <!MISSING_DEPENDENCY_CLASS!>{ <!MISSING_DEPENDENCY_CLASS!>it<!>.toString() }<!>
bar { <!MISSING_DEPENDENCY_CLASS!>some<!> -> <!MISSING_DEPENDENCY_CLASS!>some<!>.toString() }
bar <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>{ }<!>
bar { <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>_<!> -> }
bar { <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>it<!> -> }
bar <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>{ <!MISSING_DEPENDENCY_CLASS!>it<!>.toString() }<!>
bar { <!MISSING_DEPENDENCY_CLASS_IN_LAMBDA_PARAMETER!>some<!> -> <!MISSING_DEPENDENCY_CLASS!>some<!>.toString() }
}
@@ -1,5 +1,6 @@
// RENDER_DIAGNOSTICS_FULL_TEXT
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
// LANGUAGE: -ForbidLambdaParameterWithMissingDependencyType
// ISSUE: KT-64266
// MODULE: m1
@@ -0,0 +1,30 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
// LANGUAGE: +ForbidLambdaParameterWithMissingDependencyType
// ISSUE: KT-64266
// MODULE: m1
// FILE: m1.kt
class Some
// MODULE: m2(m1)
// FILE: m2.kt
fun foo(f: (Some, String) -> Unit) {}
fun bar(f: (Some) -> Unit) {}
// MODULE: m3(m2)
// FILE: m3.kt
fun test() {
foo { <!MISSING_DEPENDENCY_CLASS!>_<!>, _ -> }
foo { <!MISSING_DEPENDENCY_CLASS!>some<!>, str -> }
foo { <!MISSING_DEPENDENCY_CLASS!>some<!>, _ -> <!MISSING_DEPENDENCY_CLASS!>some<!>.toString() }
foo { some: <!UNRESOLVED_REFERENCE!>Some<!>, _ -> }
bar <!MISSING_DEPENDENCY_CLASS!>{ }<!>
bar { <!MISSING_DEPENDENCY_CLASS!>_<!> -> }
bar { <!MISSING_DEPENDENCY_CLASS!>it<!> -> }
bar <!MISSING_DEPENDENCY_CLASS!>{ <!MISSING_DEPENDENCY_CLASS!>it<!>.toString() }<!>
bar { <!MISSING_DEPENDENCY_CLASS!>some<!> -> <!MISSING_DEPENDENCY_CLASS!>some<!>.toString() }
}
@@ -0,0 +1,30 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
// LANGUAGE: +ForbidLambdaParameterWithMissingDependencyType
// ISSUE: KT-64266
// MODULE: m1
// FILE: m1.kt
class Some
// MODULE: m2(m1)
// FILE: m2.kt
fun foo(f: (Some, String) -> Unit) {}
fun bar(f: (Some) -> Unit) {}
// MODULE: m3(m2)
// FILE: m3.kt
fun test() {
foo { _, _ -> }
foo { some, str -> }
foo { some, _ -> some.toString() }
foo { some: <!UNRESOLVED_REFERENCE!>Some<!>, _ -> }
bar { }
bar { _ -> }
bar { it -> }
bar { it.toString() }
bar { some -> some.toString() }
}