Report CANNOT_INFER_PARAMETER_TYPE on any error value parameters of a lambda

^KT-48058 Fixed
This commit is contained in:
Victor Petukhov
2021-08-06 10:13:54 +03:00
committed by teamcityserver
parent 1966915e92
commit cd09c8ba51
14 changed files with 97 additions and 10 deletions
@@ -10705,6 +10705,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt4529.kt");
}
@Test
@TestMetadata("kt47493.kt")
public void testKt47493() throws Exception {
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt47493.kt");
}
@Test
@TestMetadata("kt6541_extensionForExtensionFunction.kt")
public void testKt6541_extensionForExtensionFunction() throws Exception {
@@ -10705,6 +10705,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt4529.kt");
}
@Test
@TestMetadata("kt47493.kt")
public void testKt47493() throws Exception {
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt47493.kt");
}
@Test
@TestMetadata("kt6541_extensionForExtensionFunction.kt")
public void testKt6541_extensionForExtensionFunction() throws Exception {
@@ -65,6 +65,7 @@ import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionExpression
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils.isFunctionLiteral
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
import java.util.*
@@ -446,10 +447,8 @@ class FunctionDescriptorResolver(
}
} else {
type = if (isFunctionLiteral(functionDescriptor) || isFunctionExpression(functionDescriptor)) {
val containsUninferredParameter = TypeUtils.contains(expectedType) {
TypeUtils.isDontCarePlaceholder(it) || ErrorUtils.isUninferredParameter(it)
}
if (expectedType == null || containsUninferredParameter) {
val containsErrorType = TypeUtils.contains(expectedType) { it.isError }
if (expectedType == null || containsErrorType) {
trace.report(CANNOT_INFER_PARAMETER_TYPE.on(valueParameter))
}
@@ -0,0 +1,23 @@
fun test1() {
try {
{ toDouble ->
}
} catch (e: Exception) {
}
}
fun test2() {
try {
} catch (e: Exception) {
{ toDouble ->
}
}
}
fun box(): String {
test1()
test2()
return "OK"
}
@@ -0,0 +1,23 @@
fun test1() {
try {
{ <!CANNOT_INFER_PARAMETER_TYPE!>toDouble<!> ->
}
} catch (e: Exception) {
}
}
fun test2() {
try {
} catch (e: Exception) {
{ <!CANNOT_INFER_PARAMETER_TYPE!>toDouble<!> ->
}
}
}
fun box(): String {
test1()
test2()
return "OK"
}
@@ -0,0 +1,5 @@
package
public fun box(): kotlin.String
public fun test1(): kotlin.Unit
public fun test2(): kotlin.Unit
@@ -0,0 +1,6 @@
package f
fun <R> h(i: Int, a: Any, r: R, f: (Boolean) -> Int) = 1
fun <R> h(a: Any, i: Int, r: R, f: (Boolean) -> Int) = 1
fun test() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>h<!>(1, 1, 1, { b -> 42 })
@@ -1,7 +1,6 @@
// FIR_IDENTICAL
package f
fun <R> h(i: Int, a: Any, r: R, f: (Boolean) -> Int) = 1
fun <R> h(a: Any, i: Int, r: R, f: (Boolean) -> Int) = 1
fun test() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>h<!>(1, 1, 1, { b -> 42 })
fun test() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>h<!>(1, 1, 1, { <!CANNOT_INFER_PARAMETER_TYPE!>b<!> -> 42 })
@@ -0,0 +1,9 @@
// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS
package f
fun <R> h(f: (Boolean) -> R) = 1
fun <R> h(f: (String) -> R) = 2
fun test() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>h<!>{ i -> getAnswer() }
fun getAnswer() = 42
@@ -1,10 +1,9 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -CONFLICTING_JVM_DECLARATIONS
package f
fun <R> h(f: (Boolean) -> R) = 1
fun <R> h(f: (String) -> R) = 2
fun test() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>h<!>{ i -> getAnswer() }
fun test() = <!OVERLOAD_RESOLUTION_AMBIGUITY!>h<!>{ <!CANNOT_INFER_PARAMETER_TYPE!>i<!> -> getAnswer() }
fun getAnswer() = 42
@@ -12,5 +12,5 @@ fun test1() {
fun bar(f: (<!UNRESOLVED_REFERENCE!>A<!>)->Unit) {}
fun test2() {
bar { a -> } // here we don't have 'cannot infer parameter type' error
bar { <!CANNOT_INFER_PARAMETER_TYPE!>a<!> -> } // here we don't have 'cannot infer parameter type' error
}
@@ -6,4 +6,4 @@ object X2
fun <T1> foo(x: T1, f: (T1) -> T1) = X1
fun <T2> foo(xf: () -> T2, f: (T2) -> T2) = X2
val test: X2 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>({ 0 }, { it -> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>it<!> <!DEBUG_INFO_MISSING_UNRESOLVED!>+<!> 1 })
val test: X2 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>foo<!>({ 0 }, { <!CANNOT_INFER_PARAMETER_TYPE!>it<!> -> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>it<!> <!DEBUG_INFO_MISSING_UNRESOLVED!>+<!> 1 })
@@ -10711,6 +10711,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt4529.kt");
}
@Test
@TestMetadata("kt47493.kt")
public void testKt47493() throws Exception {
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt47493.kt");
}
@Test
@TestMetadata("kt6541_extensionForExtensionFunction.kt")
public void testKt6541_extensionForExtensionFunction() throws Exception {
@@ -10705,6 +10705,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt4529.kt");
}
@Test
@TestMetadata("kt47493.kt")
public void testKt47493() throws Exception {
runTest("compiler/testData/diagnostics/tests/functionLiterals/kt47493.kt");
}
@Test
@TestMetadata("kt6541_extensionForExtensionFunction.kt")
public void testKt6541_extensionForExtensionFunction() throws Exception {