FIR2IR: add test about coercion-to-Unit for nested when

This commit is contained in:
Jinseong Jeon
2020-10-23 16:42:13 -07:00
committed by teamcityserver
parent 318f4b5f02
commit 707e94bab5
5 changed files with 229 additions and 0 deletions
@@ -1752,6 +1752,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
runTest("compiler/testData/ir/irText/firProblems/ClashResolutionDescriptor.kt");
}
@TestMetadata("coercionToUnitForNestedWhen.kt")
public void testCoercionToUnitForNestedWhen() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/coercionToUnitForNestedWhen.kt");
}
@TestMetadata("DeepCopyIrTree.kt")
public void testDeepCopyIrTree() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/DeepCopyIrTree.kt");
@@ -0,0 +1,102 @@
FILE fqName:<root> fileName:/coercionToUnitForNestedWhen.kt
PROPERTY name:BACKSLASH visibility:private modality:FINAL [const,val]
FIELD PROPERTY_BACKING_FIELD name:BACKSLASH type:kotlin.Char visibility:private [final,static]
EXPRESSION_BODY
CONST Char type=kotlin.Char value='\\'
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-BACKSLASH> visibility:private modality:FINAL <> () returnType:kotlin.Char
correspondingProperty: PROPERTY name:BACKSLASH visibility:private modality:FINAL [const,val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun <get-BACKSLASH> (): kotlin.Char declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:BACKSLASH type:kotlin.Char visibility:private [final,static]' type=kotlin.Char origin=null
FUN name:nextChar visibility:private modality:FINAL <> ($receiver:java.io.Reader) returnType:kotlin.Char?
$receiver: VALUE_PARAMETER name:<this> type:java.io.Reader
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun nextChar (): kotlin.Char? declared in <root>'
BLOCK type=kotlin.Char? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int? [val]
CALL 'public final fun takeUnless <T> (predicate: kotlin.Function1<T of kotlin.takeUnless, kotlin.Boolean>): T of kotlin.takeUnless? [inline] declared in kotlin' type=kotlin.Int? origin=null
<T>: kotlin.Int
$receiver: CALL 'public open fun read (): kotlin.Int declared in java.io.Reader' type=kotlin.Int origin=null
$this: GET_VAR '<this>: java.io.Reader declared in <root>.nextChar' type=java.io.Reader origin=null
predicate: FUN_EXPR type=kotlin.Function1<kotlin.Int, kotlin.Boolean> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:kotlin.Int) returnType:kotlin.Boolean
VALUE_PARAMETER name:it index:0 type:kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.Int): kotlin.Boolean declared in <root>.nextChar'
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'it: kotlin.Int declared in <root>.nextChar.<anonymous>' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=-1
WHEN type=kotlin.Char? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in <root>.nextChar' type=kotlin.Int? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun toChar (): kotlin.Char declared in kotlin.Int' type=kotlin.Char origin=null
$this: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in <root>.nextChar' type=kotlin.Int? origin=null
FUN name:consumeRestOfQuotedSequence visibility:public modality:FINAL <> ($receiver:java.io.Reader, sb:java.lang.StringBuilder, quote:kotlin.Char) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:<this> type:java.io.Reader
VALUE_PARAMETER name:sb index:0 type:java.lang.StringBuilder
VALUE_PARAMETER name:quote index:1 type:kotlin.Char
BLOCK_BODY
VAR name:ch type:kotlin.Char? [var]
CALL 'private final fun nextChar (): kotlin.Char? declared in <root>' type=kotlin.Char? origin=null
$receiver: GET_VAR '<this>: java.io.Reader declared in <root>.consumeRestOfQuotedSequence' type=java.io.Reader origin=null
WHILE label=null origin=WHILE_LOOP
condition: WHEN type=kotlin.Boolean origin=ANDAND
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: TYPE_OP type=kotlin.Char origin=IMPLICIT_CAST typeOperand=kotlin.Char
GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: GET_VAR 'quote: kotlin.Char declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Boolean type=kotlin.Boolean value=false
body: BLOCK type=kotlin.Unit origin=null
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
WHEN type=java.lang.StringBuilder? origin=IF
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: TYPE_OP type=kotlin.Char origin=IMPLICIT_CAST typeOperand=kotlin.Char
GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: CALL 'private final fun <get-BACKSLASH> (): kotlin.Char declared in <root>' type=kotlin.Char origin=GET_PROPERTY
then: BLOCK type=java.lang.StringBuilder? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Char? [val]
CALL 'private final fun nextChar (): kotlin.Char? declared in <root>' type=kotlin.Char? origin=null
$receiver: GET_VAR '<this>: java.io.Reader declared in <root>.consumeRestOfQuotedSequence' type=java.io.Reader origin=null
WHEN type=java.lang.StringBuilder? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_1: kotlin.Char? [val] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun let <T, R> (block: kotlin.Function1<T of kotlin.let, R of kotlin.let>): R of kotlin.let [inline] declared in kotlin' type=java.lang.StringBuilder? origin=null
<T>: kotlin.Char
<R>: java.lang.StringBuilder?
$receiver: GET_VAR 'val tmp_1: kotlin.Char? [val] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
block: FUN_EXPR type=kotlin.Function1<kotlin.Char, java.lang.StringBuilder?> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:kotlin.Char) returnType:java.lang.StringBuilder?
VALUE_PARAMETER name:it index:0 type:kotlin.Char
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.Char): java.lang.StringBuilder? declared in <root>.consumeRestOfQuotedSequence'
CALL 'public open fun append (p0: kotlin.Char): java.lang.StringBuilder? declared in java.lang.StringBuilder' type=java.lang.StringBuilder? origin=null
$this: GET_VAR 'sb: java.lang.StringBuilder declared in <root>.consumeRestOfQuotedSequence' type=java.lang.StringBuilder origin=null
p0: GET_VAR 'it: kotlin.Char declared in <root>.consumeRestOfQuotedSequence.<anonymous>' type=kotlin.Char origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun append (p0: kotlin.Char): java.lang.StringBuilder? declared in java.lang.StringBuilder' type=java.lang.StringBuilder? origin=null
$this: GET_VAR 'sb: java.lang.StringBuilder declared in <root>.consumeRestOfQuotedSequence' type=java.lang.StringBuilder origin=null
p0: TYPE_OP type=kotlin.Char origin=IMPLICIT_CAST typeOperand=kotlin.Char
GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
SET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Unit origin=EQ
CALL 'private final fun nextChar (): kotlin.Char? declared in <root>' type=kotlin.Char? origin=null
$receiver: GET_VAR '<this>: java.io.Reader declared in <root>.consumeRestOfQuotedSequence' type=java.io.Reader origin=null
@@ -0,0 +1,17 @@
// WITH_RUNTIME
// FULL_JDK
import java.io.Reader
import java.io.StringReader
private const val BACKSLASH = '\\'
private fun Reader.nextChar(): Char? =
read().takeUnless { it == -1 }?.toChar()
fun Reader.consumeRestOfQuotedSequence(sb: StringBuilder, quote: Char) {
var ch = nextChar()
while (ch != null && ch != quote) {
if (ch == BACKSLASH) nextChar()?.let { sb.append(it) } else sb.append(ch)
ch = nextChar()
}
}
@@ -0,0 +1,100 @@
FILE fqName:<root> fileName:/coercionToUnitForNestedWhen.kt
PROPERTY name:BACKSLASH visibility:private modality:FINAL [const,val]
FIELD PROPERTY_BACKING_FIELD name:BACKSLASH type:kotlin.Char visibility:private [final,static]
EXPRESSION_BODY
CONST Char type=kotlin.Char value='\\'
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-BACKSLASH> visibility:private modality:FINAL <> () returnType:kotlin.Char
correspondingProperty: PROPERTY name:BACKSLASH visibility:private modality:FINAL [const,val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun <get-BACKSLASH> (): kotlin.Char declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:BACKSLASH type:kotlin.Char visibility:private [final,static]' type=kotlin.Char origin=null
FUN name:nextChar visibility:private modality:FINAL <> ($receiver:java.io.Reader) returnType:kotlin.Char?
$receiver: VALUE_PARAMETER name:<this> type:java.io.Reader
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun nextChar (): kotlin.Char? declared in <root>'
BLOCK type=kotlin.Char? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int? [val]
CALL 'public final fun takeUnless <T> (predicate: kotlin.Function1<T of kotlin.takeUnless, kotlin.Boolean>): T of kotlin.takeUnless? [inline] declared in kotlin' type=kotlin.Int? origin=null
<T>: kotlin.Int
$receiver: CALL 'public open fun read (): kotlin.Int declared in java.io.Reader' type=kotlin.Int origin=null
$this: GET_VAR '<this>: java.io.Reader declared in <root>.nextChar' type=java.io.Reader origin=null
predicate: FUN_EXPR type=kotlin.Function1<kotlin.Int, kotlin.Boolean> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:kotlin.Int) returnType:kotlin.Boolean
VALUE_PARAMETER name:it index:0 type:kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.Int): kotlin.Boolean declared in <root>.nextChar'
CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'it: kotlin.Int declared in <root>.nextChar.<anonymous>' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=-1
WHEN type=kotlin.Char? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in <root>.nextChar' type=kotlin.Int? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun toChar (): kotlin.Char declared in kotlin.Int' type=kotlin.Char origin=null
$this: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in <root>.nextChar' type=kotlin.Int? origin=null
FUN name:consumeRestOfQuotedSequence visibility:public modality:FINAL <> ($receiver:java.io.Reader, sb:java.lang.StringBuilder{ kotlin.text.StringBuilder }, quote:kotlin.Char) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:<this> type:java.io.Reader
VALUE_PARAMETER name:sb index:0 type:java.lang.StringBuilder{ kotlin.text.StringBuilder }
VALUE_PARAMETER name:quote index:1 type:kotlin.Char
BLOCK_BODY
VAR name:ch type:kotlin.Char? [var]
CALL 'private final fun nextChar (): kotlin.Char? declared in <root>' type=kotlin.Char? origin=null
$receiver: GET_VAR '<this>: java.io.Reader declared in <root>.consumeRestOfQuotedSequence' type=java.io.Reader origin=null
WHILE label=null origin=WHILE_LOOP
condition: WHEN type=kotlin.Boolean origin=ANDAND
BRANCH
if: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: GET_VAR 'quote: kotlin.Char declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CONST Boolean type=kotlin.Boolean value=false
body: BLOCK type=kotlin.Unit origin=null
WHEN type=kotlin.Unit origin=IF
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: CALL 'private final fun <get-BACKSLASH> (): kotlin.Char declared in <root>' type=kotlin.Char origin=GET_PROPERTY
then: TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
BLOCK type=@[FlexibleNullability] java.lang.StringBuilder? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Char? [val]
CALL 'private final fun nextChar (): kotlin.Char? declared in <root>' type=kotlin.Char? origin=null
$receiver: GET_VAR '<this>: java.io.Reader declared in <root>.consumeRestOfQuotedSequence' type=java.io.Reader origin=null
WHEN type=@[FlexibleNullability] java.lang.StringBuilder? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_1: kotlin.Char? [val] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun let <T, R> (block: kotlin.Function1<T of kotlin.let, R of kotlin.let>): R of kotlin.let [inline] declared in kotlin' type=@[FlexibleNullability] java.lang.StringBuilder? origin=null
<T>: kotlin.Char
<R>: @[FlexibleNullability] java.lang.StringBuilder?
$receiver: GET_VAR 'val tmp_1: kotlin.Char? [val] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
block: FUN_EXPR type=kotlin.Function1<kotlin.Char, @[FlexibleNullability] java.lang.StringBuilder?> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:kotlin.Char) returnType:@[FlexibleNullability] java.lang.StringBuilder?
VALUE_PARAMETER name:it index:0 type:kotlin.Char
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (it: kotlin.Char): @[FlexibleNullability] java.lang.StringBuilder? declared in <root>.consumeRestOfQuotedSequence'
CALL 'public open fun append (p0: kotlin.Char): @[FlexibleNullability] java.lang.StringBuilder? declared in java.lang.StringBuilder' type=@[FlexibleNullability] java.lang.StringBuilder? origin=null
$this: GET_VAR 'sb: java.lang.StringBuilder{ kotlin.text.StringBuilder } declared in <root>.consumeRestOfQuotedSequence' type=java.lang.StringBuilder{ kotlin.text.StringBuilder } origin=null
p0: GET_VAR 'it: kotlin.Char declared in <root>.consumeRestOfQuotedSequence.<anonymous>' type=kotlin.Char origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public open fun append (p0: kotlin.Char): @[FlexibleNullability] java.lang.StringBuilder? declared in java.lang.StringBuilder' type=@[FlexibleNullability] java.lang.StringBuilder? origin=null
$this: GET_VAR 'sb: java.lang.StringBuilder{ kotlin.text.StringBuilder } declared in <root>.consumeRestOfQuotedSequence' type=java.lang.StringBuilder{ kotlin.text.StringBuilder } origin=null
p0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
SET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Unit origin=EQ
CALL 'private final fun nextChar (): kotlin.Char? declared in <root>' type=kotlin.Char? origin=null
$receiver: GET_VAR '<this>: java.io.Reader declared in <root>.consumeRestOfQuotedSequence' type=java.io.Reader origin=null
@@ -1751,6 +1751,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
runTest("compiler/testData/ir/irText/firProblems/ClashResolutionDescriptor.kt");
}
@TestMetadata("coercionToUnitForNestedWhen.kt")
public void testCoercionToUnitForNestedWhen() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/coercionToUnitForNestedWhen.kt");
}
@TestMetadata("DeepCopyIrTree.kt")
public void testDeepCopyIrTree() throws Exception {
runTest("compiler/testData/ir/irText/firProblems/DeepCopyIrTree.kt");