Unwrap block expressions to report errors on them about not enough type information

^KT-44055 Fixed
This commit is contained in:
Victor Petukhov
2020-12-24 13:47:48 +03:00
parent 4c56962678
commit 9afc13f002
3 changed files with 63 additions and 1 deletions
@@ -461,7 +461,11 @@ class DiagnosticReporterByTrackingStrategy(
is TypeVariableForLambdaReturnType -> "return type of lambda"
else -> error("Unsupported type variable: $typeVariable")
}
trace.reportDiagnosticOnce(NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER.on(expression, typeVariableName))
val unwrappedExpression = if (expression is KtBlockExpression) {
expression.statements.lastOrNull() ?: expression
} else expression
trace.reportDiagnosticOnce(NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER.on(unwrappedExpression, typeVariableName))
}
}
@@ -0,0 +1,29 @@
// WITH_RUNTIME
// SKIP_TXT
// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS
import kotlin.experimental.ExperimentalTypeInference
class Foo7<T>
fun foo7() = null as Foo7<Int>
fun poll17(flag: Boolean): Any? {
val inv = if (flag) { foo7() } else { ::Foo7 }
return inv
}
fun poll26(flag: Boolean): Any? {
val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 }
return inv
}
fun poll36(flag: Boolean): Any? {
val inv = when (flag) { true -> ::Foo7 false -> foo7() }
return inv
}
fun poll56(): Any? {
val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() }
return inv
}
@@ -0,0 +1,29 @@
// WITH_RUNTIME
// SKIP_TXT
// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS
import kotlin.experimental.ExperimentalTypeInference
class Foo7<T>
fun foo7() = null as Foo7<Int>
fun poll17(flag: Boolean): Any? {
val inv = if (flag) { <!IMPLICIT_CAST_TO_ANY!>foo7()<!> } else { <!IMPLICIT_CAST_TO_ANY!>::Foo7<!> }
return inv
}
fun poll26(flag: Boolean): Any? {
val inv = when (flag) { true -> <!IMPLICIT_CAST_TO_ANY, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>::Foo7<!> false -> <!IMPLICIT_CAST_TO_ANY!>foo7()<!> <!REDUNDANT_ELSE_IN_WHEN!>else<!> -> <!IMPLICIT_CAST_TO_ANY, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>::Foo7<!> }
return inv
}
fun poll36(flag: Boolean): Any? {
val inv = when (flag) { true -> <!IMPLICIT_CAST_TO_ANY, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>::Foo7<!> false -> <!IMPLICIT_CAST_TO_ANY!>foo7()<!> }
return inv
}
fun poll56(): Any? {
val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() }
return inv
}