FIR: Fix incorrectly serialized type
See the test added: there's a non-denotable T!! type inside flexible type that wasn't handled before. ConeKotlinType::contains handles flexible types content and some other cases Also, it has better asymptotics
This commit is contained in:
+6
@@ -33314,6 +33314,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/regressions/approximateIntersectionType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("approximationForDefinitelyNotNull.kt")
|
||||
public void testApproximationForDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/regressions/approximationForDefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayLengthNPE.kt")
|
||||
public void testArrayLengthNPE() throws Exception {
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.classId
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.classId
|
||||
import org.jetbrains.kotlin.fir.fakeElement
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
@@ -270,17 +269,8 @@ fun FirTypeRef.approximatedForPublicPosition(approximator: AbstractTypeApproxima
|
||||
else
|
||||
this
|
||||
|
||||
private fun ConeKotlinType.requiresApproximationInPublicPosition(): Boolean {
|
||||
return when (this) {
|
||||
is ConeIntegerLiteralType,
|
||||
is ConeCapturedType,
|
||||
is ConeDefinitelyNotNullType,
|
||||
is ConeIntersectionType -> true
|
||||
is ConeClassLikeType -> typeArguments.any {
|
||||
it is ConeKotlinTypeProjection && it.type.requiresApproximationInPublicPosition()
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
private fun ConeKotlinType.requiresApproximationInPublicPosition(): Boolean = contains {
|
||||
it is ConeIntegerLiteralType || it is ConeCapturedType || it is ConeDefinitelyNotNullType || it is ConeIntersectionType
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
// MODULE: lib
|
||||
// FILE: CachedValuesManager.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
public class CachedValuesManager {
|
||||
public @NotNull <T> CachedValue<T> createCachedValue(final @NotNull CachedValueProvider<T> provider) {
|
||||
return new CachedValue<T>() {
|
||||
public T getValue() {
|
||||
return provider.compute().value;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: CachedValueProvider.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface CachedValueProvider<T> {
|
||||
@Nullable
|
||||
Result<T> compute();
|
||||
|
||||
class Result<T> {
|
||||
public final T value;
|
||||
public Result(@Nullable T value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: CachedValue.java
|
||||
public interface CachedValue<T> {
|
||||
T getValue();
|
||||
}
|
||||
|
||||
// FILE: lib.kt
|
||||
|
||||
// Inferred as CachedValue<ft<T!!, T>>! and T!! should be approximated
|
||||
fun <T> cachedValue(manager: CachedValuesManager, createValue: () -> T) =
|
||||
manager.createCachedValue {
|
||||
CachedValueProvider.Result(
|
||||
createValue()
|
||||
)
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
|
||||
fun box(): String {
|
||||
val value = cachedValue(CachedValuesManager()) { Pair("O", "K") }.value
|
||||
|
||||
return value.first + value.second
|
||||
}
|
||||
+6
@@ -33514,6 +33514,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/regressions/approximateIntersectionType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("approximationForDefinitelyNotNull.kt")
|
||||
public void testApproximationForDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/regressions/approximationForDefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayLengthNPE.kt")
|
||||
public void testArrayLengthNPE() throws Exception {
|
||||
|
||||
+6
@@ -33314,6 +33314,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/regressions/approximateIntersectionType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("approximationForDefinitelyNotNull.kt")
|
||||
public void testApproximationForDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/regressions/approximationForDefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayLengthNPE.kt")
|
||||
public void testArrayLengthNPE() throws Exception {
|
||||
|
||||
+5
@@ -27298,6 +27298,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/regressions/approximateIntersectionType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("approximationForDefinitelyNotNull.kt")
|
||||
public void testApproximationForDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/regressions/approximationForDefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayLengthNPE.kt")
|
||||
public void testArrayLengthNPE() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/regressions/arrayLengthNPE.kt");
|
||||
|
||||
-1
@@ -74,7 +74,6 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/comments.kt");
|
||||
}
|
||||
|
||||
/** Regression test for KT-43593. */
|
||||
@TestMetadata("commentsRemoved.kt")
|
||||
public void testCommentsRemoved() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/commentsRemoved.kt");
|
||||
|
||||
-1
@@ -75,7 +75,6 @@ public class IrClassFileToSourceStubConverterTestGenerated extends AbstractIrCla
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/comments.kt");
|
||||
}
|
||||
|
||||
/** Regression test for KT-43593. */
|
||||
@TestMetadata("commentsRemoved.kt")
|
||||
public void testCommentsRemoved() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-compiler/testData/converter/commentsRemoved.kt");
|
||||
|
||||
Reference in New Issue
Block a user