[FE 1.0] Correctly set USED_AS_EXPRESSION for unreachable when and if blocks
^KT-50028 Fixed
This commit is contained in:
committed by
teamcity
parent
7bcd3c7948
commit
df2e9e3797
Generated
+6
@@ -1658,6 +1658,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt49203.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt50028.kt")
|
||||
public void testKt50028() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt50028.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInCAO.kt")
|
||||
public void testLambdaInCAO() throws Exception {
|
||||
|
||||
+21
-5
@@ -812,17 +812,33 @@ class ControlFlowInformationProviderImpl private constructor(
|
||||
for (element in pseudocode.getValueElements(value)) {
|
||||
trace.record(USED_AS_EXPRESSION, element, isUsedAsExpression)
|
||||
trace.record(USED_AS_RESULT_OF_LAMBDA, element, isUsedAsResultOfLambda)
|
||||
if (isUsedAsExpression && element is KtTryExpression) {
|
||||
trace.record(USED_AS_EXPRESSION, element.tryBlock, true)
|
||||
for (catchClause in element.catchClauses) {
|
||||
val body = catchClause.catchBody ?: continue
|
||||
trace.record(USED_AS_EXPRESSION, body, true)
|
||||
if (isUsedAsExpression) {
|
||||
when (element) {
|
||||
is KtTryExpression -> {
|
||||
element.tryBlock.recordUsedAsExpression()
|
||||
for (catchClause in element.catchClauses) {
|
||||
catchClause.catchBody?.recordUsedAsExpression()
|
||||
}
|
||||
}
|
||||
is KtIfExpression -> {
|
||||
(element.then as? KtBlockExpression)?.recordUsedAsExpression()
|
||||
(element.`else` as? KtBlockExpression)?.recordUsedAsExpression()
|
||||
}
|
||||
is KtWhenExpression -> {
|
||||
for (entry in element.entries) {
|
||||
(entry.expression as? KtBlockExpression)?.recordUsedAsExpression()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtExpression.recordUsedAsExpression() {
|
||||
trace.record(USED_AS_EXPRESSION, this, true)
|
||||
}
|
||||
|
||||
private fun checkForSuspendLambdaAndMarkParameters(pseudocode: Pseudocode) {
|
||||
for (instruction in pseudocode.instructionsIncludingDeadCode) {
|
||||
if (instruction is LocalFunctionDeclarationInstruction) {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// IGNORE_BACKEND: WASM
|
||||
// WASM_MUTE_REASON: STRANGE_IMPLICIT_CAST
|
||||
|
||||
fun kt49182(x: Boolean): String {
|
||||
return if (x) {
|
||||
return "O"
|
||||
@@ -23,4 +20,4 @@ fun box(): String {
|
||||
exit()
|
||||
}
|
||||
return a
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
FILE fqName:<root> fileName:/kt50028.kt
|
||||
FUN name:test_1 visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test_1 (): kotlin.String declared in <root>'
|
||||
WHEN type=kotlin.Nothing origin=WHEN
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: RETURN type=kotlin.Nothing from='public final fun test_1 (): kotlin.String declared in <root>'
|
||||
CONST String type=kotlin.String value=""
|
||||
FUN name:test_2 visibility:public modality:FINAL <> (b:kotlin.Boolean) returnType:kotlin.Boolean
|
||||
VALUE_PARAMETER name:b index:0 type:kotlin.Boolean
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test_2 (b: kotlin.Boolean): kotlin.Boolean declared in <root>'
|
||||
WHEN type=kotlin.Boolean origin=IF
|
||||
BRANCH
|
||||
if: GET_VAR 'b: kotlin.Boolean declared in <root>.test_2' type=kotlin.Boolean origin=null
|
||||
then: CONST Boolean type=kotlin.Boolean value=true
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: THROW type=kotlin.Nothing
|
||||
CONSTRUCTOR_CALL 'public constructor <init> (message: kotlin.String) [primary] declared in kotlin.NotImplementedError' type=kotlin.NotImplementedError origin=null
|
||||
@@ -0,0 +1,12 @@
|
||||
fun test_1(): String {
|
||||
return when {
|
||||
else -> return ""
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2(b: Boolean): Boolean {
|
||||
return when {
|
||||
b -> true
|
||||
else -> throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
FILE fqName:<root> fileName:/kt50028.kt
|
||||
FUN name:test_1 visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test_1 (): kotlin.String declared in <root>'
|
||||
WHEN type=kotlin.String origin=WHEN
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: BLOCK type=kotlin.Nothing origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun test_1 (): kotlin.String declared in <root>'
|
||||
CONST String type=kotlin.String value=""
|
||||
FUN name:test_2 visibility:public modality:FINAL <> (b:kotlin.Boolean) returnType:kotlin.Boolean
|
||||
VALUE_PARAMETER name:b index:0 type:kotlin.Boolean
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test_2 (b: kotlin.Boolean): kotlin.Boolean declared in <root>'
|
||||
WHEN type=kotlin.Boolean origin=IF
|
||||
BRANCH
|
||||
if: GET_VAR 'b: kotlin.Boolean declared in <root>.test_2' type=kotlin.Boolean origin=null
|
||||
then: BLOCK type=kotlin.Boolean origin=null
|
||||
CONST Boolean type=kotlin.Boolean value=true
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: BLOCK type=kotlin.Nothing origin=null
|
||||
THROW type=kotlin.Nothing
|
||||
CONSTRUCTOR_CALL 'public constructor <init> (message: kotlin.String) [primary] declared in kotlin.NotImplementedError' type=kotlin.NotImplementedError origin=null
|
||||
@@ -0,0 +1,17 @@
|
||||
// ISSUE: KT-50028
|
||||
|
||||
fun test_1(): String {
|
||||
return when {
|
||||
else -> {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2(b: Boolean): Boolean {
|
||||
return if (b) {
|
||||
true
|
||||
} else {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fun test_1(): String {
|
||||
return when {
|
||||
else -> { // BLOCK
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2(b: Boolean): Boolean {
|
||||
return when {
|
||||
b -> { // BLOCK
|
||||
true
|
||||
}
|
||||
else -> { // BLOCK
|
||||
throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -1658,6 +1658,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt49203.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt50028.kt")
|
||||
public void testKt50028() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt50028.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaInCAO.kt")
|
||||
public void testLambdaInCAO() throws Exception {
|
||||
|
||||
@@ -1247,6 +1247,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt49203.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt50028.kt")
|
||||
public void testKt50028() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt50028.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaInCAO.kt")
|
||||
public void testLambdaInCAO() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/lambdaInCAO.kt");
|
||||
|
||||
Reference in New Issue
Block a user