[FIR] Use Throwable as expected type for throw expressions

#KT-58533 Fixed
This commit is contained in:
Kirill Rakhman
2023-05-22 10:59:56 +02:00
committed by Space Team
parent 55632f5df2
commit 7a9c516f68
10 changed files with 49 additions and 5 deletions
@@ -14618,6 +14618,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt"); runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
} }
@Test
@TestMetadata("genericCallInThrow.kt")
public void testGenericCallInThrow() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericCallInThrow.kt");
}
@Test @Test
@TestMetadata("hasErrorInConstrainingTypes.kt") @TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception { public void testHasErrorInConstrainingTypes() throws Exception {
@@ -14618,6 +14618,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt"); runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
} }
@Test
@TestMetadata("genericCallInThrow.kt")
public void testGenericCallInThrow() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericCallInThrow.kt");
}
@Test @Test
@TestMetadata("hasErrorInConstrainingTypes.kt") @TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception { public void testHasErrorInConstrainingTypes() throws Exception {
@@ -14618,6 +14618,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt"); runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
} }
@Test
@TestMetadata("genericCallInThrow.kt")
public void testGenericCallInThrow() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericCallInThrow.kt");
}
@Test @Test
@TestMetadata("hasErrorInConstrainingTypes.kt") @TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception { public void testHasErrorInConstrainingTypes() throws Exception {
@@ -14624,6 +14624,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt"); runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
} }
@Test
@TestMetadata("genericCallInThrow.kt")
public void testGenericCallInThrow() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericCallInThrow.kt");
}
@Test @Test
@TestMetadata("hasErrorInConstrainingTypes.kt") @TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception { public void testHasErrorInConstrainingTypes() throws Exception {
@@ -218,10 +218,13 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirAbstractBodyRes
override fun transformThrowExpression( override fun transformThrowExpression(
throwExpression: FirThrowExpression, throwExpression: FirThrowExpression,
data: ResolutionMode data: ResolutionMode,
): FirStatement { ): FirStatement {
return transformer.transformExpression(throwExpression, ResolutionMode.ContextIndependent).also { return throwExpression.apply {
dataFlowAnalyzer.exitThrowExceptionNode(it as FirThrowExpression) replaceTypeRef(throwExpression.typeRef.transform(transformer, data))
transformAnnotations(transformer, data)
transformException(transformer, withExpectedType(session.builtinTypes.throwableType))
dataFlowAnalyzer.exitThrowExceptionNode(this)
} }
} }
@@ -32,4 +32,6 @@ abstract class FirThrowExpression : FirExpression() {
abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirThrowExpression abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirThrowExpression
abstract fun <D> transformException(transformer: FirTransformer<D>, data: D): FirThrowExpression
} }
@@ -40,7 +40,7 @@ internal class FirThrowExpressionImpl(
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirThrowExpressionImpl { override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirThrowExpressionImpl {
typeRef = typeRef.transform(transformer, data) typeRef = typeRef.transform(transformer, data)
transformAnnotations(transformer, data) transformAnnotations(transformer, data)
exception = exception.transform(transformer, data) transformException(transformer, data)
return this return this
} }
@@ -49,6 +49,11 @@ internal class FirThrowExpressionImpl(
return this return this
} }
override fun <D> transformException(transformer: FirTransformer<D>, data: D): FirThrowExpressionImpl {
exception = exception.transform(transformer, data)
return this
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) { override fun replaceTypeRef(newTypeRef: FirTypeRef) {
typeRef = newTypeRef typeRef = newTypeRef
} }
@@ -620,7 +620,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
} }
throwExpression.configure { throwExpression.configure {
+field("exception", expression) +field("exception", expression).withTransform()
} }
variableAssignment.configure { variableAssignment.configure {
@@ -0,0 +1,4 @@
// FIR_IDENTICAL
fun <T> a(): T = TODO()
val b: Unit = throw a()
@@ -14624,6 +14624,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt"); runTest("compiler/testData/diagnostics/tests/inference/genericAssignmentOperator.kt");
} }
@Test
@TestMetadata("genericCallInThrow.kt")
public void testGenericCallInThrow() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/genericCallInThrow.kt");
}
@Test @Test
@TestMetadata("hasErrorInConstrainingTypes.kt") @TestMetadata("hasErrorInConstrainingTypes.kt")
public void testHasErrorInConstrainingTypes() throws Exception { public void testHasErrorInConstrainingTypes() throws Exception {