[FIR2IR] Correctly calculate offsets for implicit toLong() calls during constant evaluation
^KT-58132 Fixed
This commit is contained in:
committed by
Space Team
parent
4fe239375f
commit
903e969598
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.expressions.FirExpression
|
|||||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
|
||||||
import org.jetbrains.kotlin.fir.packageFqName
|
import org.jetbrains.kotlin.fir.packageFqName
|
||||||
import org.jetbrains.kotlin.fir.serialization.constant.ConstValueProvider
|
import org.jetbrains.kotlin.fir.serialization.constant.ConstValueProvider
|
||||||
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
class ConstValueProviderImpl(
|
class ConstValueProviderImpl(
|
||||||
@@ -28,7 +29,7 @@ class ConstValueProviderImpl(
|
|||||||
return if (firExpression is FirQualifiedAccessExpression) {
|
return if (firExpression is FirQualifiedAccessExpression) {
|
||||||
// TODO check that this behavior is expected in ConversionUtils and if not fix it
|
// TODO check that this behavior is expected in ConversionUtils and if not fix it
|
||||||
val calleeReference = firExpression.calleeReference
|
val calleeReference = firExpression.calleeReference
|
||||||
val start = calleeReference.source?.startOffsetSkippingComments() ?: calleeReference.source?.startOffset ?: return null
|
val start = calleeReference.source?.startOffsetSkippingComments() ?: calleeReference.source?.startOffset ?: UNDEFINED_OFFSET
|
||||||
val end = firExpression.source?.endOffset ?: return null
|
val end = firExpression.source?.endOffset ?: return null
|
||||||
evaluatedConstTracker.load(start, end, fileName)
|
evaluatedConstTracker.load(start, end, fileName)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+6
@@ -8409,6 +8409,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -8409,6 +8409,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// ISSUE: KT-58132
|
||||||
|
|
||||||
|
const val hourInMilliseconds: Long = 60 * 60 * 1000
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val expected = 3600000L
|
||||||
|
return if (hourInMilliseconds == expected) "OK" else "Fail: $hourInMilliseconds"
|
||||||
|
}
|
||||||
+6
@@ -8193,6 +8193,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -8409,6 +8409,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -8409,6 +8409,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+5
@@ -6259,6 +6259,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/constants/long.kt");
|
runTest("compiler/testData/codegen/box/constants/long.kt");
|
||||||
|
|||||||
+6
@@ -5411,6 +5411,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -5471,6 +5471,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -5471,6 +5471,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -5471,6 +5471,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -6452,6 +6452,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -6598,6 +6598,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -6379,6 +6379,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
+6
@@ -6525,6 +6525,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
|
|||||||
Generated
+5
@@ -4819,6 +4819,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
runTest("compiler/testData/codegen/box/constants/kt9532.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("literalToLongConversion.kt")
|
||||||
|
public void testLiteralToLongConversion() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/constants/literalToLongConversion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("long.kt")
|
@TestMetadata("long.kt")
|
||||||
public void testLong() throws Exception {
|
public void testLong() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/constants/long.kt");
|
runTest("compiler/testData/codegen/box/constants/long.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user