Check if the intersecting types aren't empty during finding the result type for variable fixation
^KT-47941 Fixed
This commit is contained in:
committed by
teamcityserver
parent
3eaa452f9e
commit
93f9d9dacd
+6
@@ -15234,6 +15234,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt47941.kt")
|
||||||
|
public void testKt47941() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt47941.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt702.kt")
|
@TestMetadata("kt702.kt")
|
||||||
public void testKt702() throws Exception {
|
public void testKt702() throws Exception {
|
||||||
|
|||||||
+6
@@ -15234,6 +15234,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt47941.kt")
|
||||||
|
public void testKt47941() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt47941.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt702.kt")
|
@TestMetadata("kt702.kt")
|
||||||
public void testKt702() throws Exception {
|
public void testKt702() throws Exception {
|
||||||
|
|||||||
+2
-1
@@ -265,7 +265,8 @@ class ResultTypeResolver(
|
|||||||
* fun <T : String> materialize(): T = null as T
|
* fun <T : String> materialize(): T = null as T
|
||||||
* val bar: Int = materialize() // no errors, T is inferred into String & Int
|
* val bar: Int = materialize() // no errors, T is inferred into String & Int
|
||||||
*/
|
*/
|
||||||
intersectTypes(upperConstraints.filterNot { it.isExpectedTypePosition() }.map { it.type })
|
val filteredUpperConstraints = upperConstraints.filterNot { it.isExpectedTypePosition() }.map { it.type }
|
||||||
|
if (filteredUpperConstraints.isNotEmpty()) intersectTypes(filteredUpperConstraints) else intersectionUpperType
|
||||||
} else intersectionUpperType
|
} else intersectionUpperType
|
||||||
|
|
||||||
return typeApproximator.approximateToSubType(
|
return typeApproximator.approximateToSubType(
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNCHECKED_CAST
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
sealed interface Metric {}
|
||||||
|
|
||||||
|
class Counter: Metric
|
||||||
|
class Gauge<T>: Metric
|
||||||
|
|
||||||
|
fun <K> foo(y: List<K?>, x: Inv<in K?>, p: (Inv<K?>, K?) -> Unit) {}
|
||||||
|
fun <M> materialize(): M = null as M
|
||||||
|
|
||||||
|
class Inv<L>(var x: L)
|
||||||
|
|
||||||
|
fun <T : Metric?> register(name: String, metric: T): T? {
|
||||||
|
when (metric) {
|
||||||
|
is Counter -> {
|
||||||
|
return metric
|
||||||
|
}
|
||||||
|
is Gauge<*> -> {
|
||||||
|
foo(listOf(), Inv(metric)) { x, y ->
|
||||||
|
var a = y
|
||||||
|
a = materialize()
|
||||||
|
}
|
||||||
|
return metric
|
||||||
|
}
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun </*0*/ K> foo(/*0*/ y: kotlin.collections.List<K?>, /*1*/ x: Inv<in K?>, /*2*/ p: (Inv<K?>, K?) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public fun </*0*/ M> materialize(): M
|
||||||
|
public fun </*0*/ T : Metric?> register(/*0*/ name: kotlin.String, /*1*/ metric: T): T?
|
||||||
|
|
||||||
|
public final class Counter : Metric {
|
||||||
|
public constructor Counter()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class Gauge</*0*/ T> : Metric {
|
||||||
|
public constructor Gauge</*0*/ T>()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class Inv</*0*/ L> {
|
||||||
|
public constructor Inv</*0*/ L>(/*0*/ x: L)
|
||||||
|
public final var x: L
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed interface Metric {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
Generated
+6
@@ -15240,6 +15240,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt47941.kt")
|
||||||
|
public void testKt47941() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt47941.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt702.kt")
|
@TestMetadata("kt702.kt")
|
||||||
public void testKt702() throws Exception {
|
public void testKt702() throws Exception {
|
||||||
|
|||||||
+6
@@ -15234,6 +15234,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt44440.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt47941.kt")
|
||||||
|
public void testKt47941() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inference/regressions/kt47941.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("kt702.kt")
|
@TestMetadata("kt702.kt")
|
||||||
public void testKt702() throws Exception {
|
public void testKt702() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user