[FIR] Expand typealias for correct approximation of types (particularly Int and Long)

This commit is contained in:
Ivan Kochurkin
2021-09-13 17:02:23 +03:00
committed by Space
parent 3d58a70e62
commit 07edb15138
7 changed files with 36 additions and 1 deletions
@@ -30669,6 +30669,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt");
}
@Test
@TestMetadata("intToLongApproximationThroughTypeAlias.kt")
public void testIntToLongApproximationThroughTypeAlias() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/intToLongApproximationThroughTypeAlias.kt");
}
@Test
@TestMetadata("isAsWithTypeAlias.kt")
public void testIsAsWithTypeAlias() throws Exception {
@@ -30669,6 +30669,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt");
}
@Test
@TestMetadata("intToLongApproximationThroughTypeAlias.kt")
public void testIntToLongApproximationThroughTypeAlias() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/intToLongApproximationThroughTypeAlias.kt");
}
@Test
@TestMetadata("isAsWithTypeAlias.kt")
public void testIsAsWithTypeAlias() throws Exception {
@@ -877,7 +877,8 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
val integerLiteralType =
ConeIntegerLiteralTypeImpl(constExpression.value as Long, isUnsigned = kind == ConstantValueKind.UnsignedIntegerLiteral)
if (data.expectedType != null) {
val approximatedType = integerLiteralType.getApproximatedType(data.expectedType?.coneTypeSafe())
val coneType = data.expectedType?.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session)
val approximatedType = integerLiteralType.getApproximatedType(coneType)
val newConstKind = approximatedType.toConstKind()
@Suppress("UNCHECKED_CAST")
constExpression.replaceKind(newConstKind as ConstantValueKind<T>)
@@ -0,0 +1,6 @@
// FIR_IDENTICAL
typealias Hash = Long
fun foo(): Hash {
return 0
}
@@ -0,0 +1,4 @@
package
public fun foo(): Hash /* = kotlin.Long */
public typealias Hash = kotlin.Long
@@ -30765,6 +30765,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt");
}
@Test
@TestMetadata("intToLongApproximationThroughTypeAlias.kt")
public void testIntToLongApproximationThroughTypeAlias() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/intToLongApproximationThroughTypeAlias.kt");
}
@Test
@TestMetadata("isAsWithTypeAlias.kt")
public void testIsAsWithTypeAlias() throws Exception {
@@ -30669,6 +30669,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/typealias/innerTypeAliasConstructor.kt");
}
@Test
@TestMetadata("intToLongApproximationThroughTypeAlias.kt")
public void testIntToLongApproximationThroughTypeAlias() throws Exception {
runTest("compiler/testData/diagnostics/tests/typealias/intToLongApproximationThroughTypeAlias.kt");
}
@Test
@TestMetadata("isAsWithTypeAlias.kt")
public void testIsAsWithTypeAlias() throws Exception {