[FIR] Report empty intersection on responsible call

When reporting INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION, search
for a call to a declaration with the type parameter that got inferred
into an empty intersection inside the expression.

#KT-56377 Fixed
This commit is contained in:
Kirill Rakhman
2023-06-20 09:44:48 +02:00
committed by Space Team
parent 3f58782273
commit 585d4b3098
13 changed files with 187 additions and 8 deletions
@@ -0,0 +1,34 @@
// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection
// FILE: ObjectNode.java
public interface ObjectNode {
<T extends JsonNode> T set(String fieldName, JsonNode value);
}
// FILE: JsonNode.java
public class JsonNode
// FILE: test.kt
interface JsonObject
class SomeJsonObject() : JsonObject
fun String.put(value: JsonObject?, node: ObjectNode) {
select(
node.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>set<!>(this, null),
Unit,
)
if (value == null) node.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>set<!>(this, null)
else if (value is SomeJsonObject) Unit
when (value) {
null -> node.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>set<!>(this, null)
is SomeJsonObject -> Unit
else -> TODO()
}
}
fun TODO(): Nothing = null!!
fun <K> select(vararg values: K): K = values[0]
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidInferringTypeVariablesIntoEmptyIntersection
// FILE: ObjectNode.java
@@ -16,6 +15,14 @@ interface JsonObject
class SomeJsonObject() : JsonObject
fun String.put(value: JsonObject?, node: ObjectNode) {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>select<!>(
node.set(this, null),
Unit,
)
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>if (value == null) node.set(this, null)
else if (value is SomeJsonObject) Unit<!>
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_ERROR!>when (value) {
null -> node.set(this, null)
is SomeJsonObject -> Unit
@@ -24,3 +31,4 @@ fun String.put(value: JsonObject?, node: ObjectNode) {
}
fun TODO(): Nothing = null!!
fun <K> select(vararg values: K): K = values[0]
@@ -1,6 +1,7 @@
package
public fun TODO(): kotlin.Nothing
public fun </*0*/ K> select(/*0*/ vararg values: K /*kotlin.Array<out K>*/): K
public fun kotlin.String.put(/*0*/ value: JsonObject?, /*1*/ node: ObjectNode): kotlin.Unit
public open class JsonNode {
@@ -0,0 +1,35 @@
// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection
// FILE: ObjectNode.java
public interface ObjectNode {
<T extends JsonNode> T set(String fieldName, JsonNode value);
}
// FILE: JsonNode.java
public class JsonNode
// FILE: test.kt
interface JsonObject
class SomeJsonObject() : JsonObject
fun String.put(value: JsonObject?, node: ObjectNode) {
select(
node.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>set<!>(this, null),
Unit,
)
if (value == null) node.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>set<!>(this, null)
else if (value is SomeJsonObject) Unit
when (value) {
null -> node.<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>set<!>(this, null)
is SomeJsonObject -> Unit
else -> TODO()
}
}
fun TODO(): Nothing = null!!
fun <K> select(vararg values: K): K = values[0]
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
// !LANGUAGE: -ForbidInferringTypeVariablesIntoEmptyIntersection
// FILE: ObjectNode.java
@@ -16,6 +15,14 @@ interface JsonObject
class SomeJsonObject() : JsonObject
fun String.put(value: JsonObject?, node: ObjectNode) {
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>select<!>(
node.set(this, null),
Unit,
)
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>if (value == null) node.set(this, null)
else if (value is SomeJsonObject) Unit<!>
<!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING!>when (value) {
null -> node.set(this, null)
is SomeJsonObject -> Unit
@@ -24,3 +31,5 @@ fun String.put(value: JsonObject?, node: ObjectNode) {
}
fun TODO(): Nothing = null!!
fun <K> select(vararg values: K): K = values[0]