From 618295f505821096dc9649e52eb7bcf795a11d83 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 11 Apr 2019 16:56:19 +0300 Subject: [PATCH] FIR: implement trivial typing for break & continue --- .../fir/expressions/impl/FirAbstractLoopJump.kt | 5 ++++- .../ir/irText/expressions/badBreakContinue.fir.txt | 4 ++-- .../ir/irText/expressions/breakContinue.fir.txt | 12 ++++++------ .../expressions/breakContinueInLoopHeader.fir.txt | 12 ++++++------ .../irText/expressions/forWithBreakContinue.fir.txt | 12 ++++++------ 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoopJump.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoopJump.kt index 704babc352b..a6529f44788 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoopJump.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAbstractLoopJump.kt @@ -6,15 +6,18 @@ package org.jetbrains.kotlin.fir.expressions.impl import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.fir.FirAbstractElement import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirTarget import org.jetbrains.kotlin.fir.expressions.FirJump import org.jetbrains.kotlin.fir.expressions.FirLoop +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.impl.FirImplicitNothingTypeRef abstract class FirAbstractLoopJump( session: FirSession, psi: PsiElement? ) : FirAbstractExpression(session, psi), FirJump { override lateinit var target: FirTarget + + override var typeRef: FirTypeRef = FirImplicitNothingTypeRef(session, psi) } \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt index 47177edb249..20664ce9b7d 100644 --- a/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt +++ b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.txt @@ -7,7 +7,7 @@ FILE fqName: fileName:/badBreakContinue.kt BLOCK_BODY WHILE label=L1 origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Unit @@ -20,7 +20,7 @@ FILE fqName: fileName:/badBreakContinue.kt FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:IrErrorType BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): IrErrorType declared in .test3' - BLOCK type=IrErrorType origin=null + BLOCK type=kotlin.Nothing origin=null BREAK label=L1 loop.label=L1 CONTINUE label=L1 loop.label=L1 FUNCTION_REFERENCE 'local final fun (): IrErrorType declared in .test3' type=IrErrorType origin=LAMBDA diff --git a/compiler/testData/ir/irText/expressions/breakContinue.fir.txt b/compiler/testData/ir/irText/expressions/breakContinue.fir.txt index 3614399c376..dfd2a27515b 100644 --- a/compiler/testData/ir/irText/expressions/breakContinue.fir.txt +++ b/compiler/testData/ir/irText/expressions/breakContinue.fir.txt @@ -17,19 +17,19 @@ FILE fqName: fileName:/breakContinue.kt BLOCK_BODY WHILE label=OUTER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null WHILE label=INNER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null BREAK label=INNER loop.label=INNER BREAK label=OUTER loop.label=OUTER BREAK label=OUTER loop.label=OUTER WHILE label=OUTER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null WHILE label=INNER origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null CONTINUE label=INNER loop.label=INNER CONTINUE label=OUTER loop.label=OUTER CONTINUE label=OUTER loop.label=OUTER @@ -37,14 +37,14 @@ FILE fqName: fileName:/breakContinue.kt BLOCK_BODY WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true body: BREAK label=L loop.label=L BREAK label=L loop.label=L WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true body: CONTINUE label=L loop.label=L diff --git a/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt index 8d849af37d8..2913692e10b 100644 --- a/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt +++ b/compiler/testData/ir/irText/expressions/breakContinueInLoopHeader.fir.txt @@ -45,11 +45,11 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true body: BLOCK type=kotlin.Unit origin=null - VAR name: type:IrErrorType [val] - BLOCK type=IrErrorType origin=ELVIS + VAR name: type:kotlin.Nothing [val] + BLOCK type=kotlin.Nothing origin=ELVIS VAR name: type:kotlin.collections.List? [val] GET_VAR 'ss: kotlin.collections.List? declared in .test3' type=kotlin.collections.List? origin=null - WHEN type=IrErrorType origin=ELVIS + WHEN type=kotlin.Nothing origin=ELVIS 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 : kotlin.collections.List? [val] declared in .test3' type=kotlin.collections.List? origin=null @@ -71,11 +71,11 @@ FILE fqName: fileName:/breakContinueInLoopHeader.kt WHILE label=L origin=WHILE_LOOP condition: CONST Boolean type=kotlin.Boolean value=true body: BLOCK type=kotlin.Unit origin=null - VAR name: type:IrErrorType [val] - BLOCK type=IrErrorType origin=ELVIS + VAR name: type:kotlin.Nothing [val] + BLOCK type=kotlin.Nothing origin=ELVIS VAR name: type:kotlin.collections.List? [val] GET_VAR 'ss: kotlin.collections.List? declared in .test4' type=kotlin.collections.List? origin=null - WHEN type=IrErrorType origin=ELVIS + WHEN type=kotlin.Nothing origin=ELVIS 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 : kotlin.collections.List? [val] declared in .test4' type=kotlin.collections.List? origin=null diff --git a/compiler/testData/ir/irText/expressions/forWithBreakContinue.fir.txt b/compiler/testData/ir/irText/expressions/forWithBreakContinue.fir.txt index ae814c99472..889a44d67e0 100644 --- a/compiler/testData/ir/irText/expressions/forWithBreakContinue.fir.txt +++ b/compiler/testData/ir/irText/expressions/forWithBreakContinue.fir.txt @@ -8,7 +8,7 @@ FILE fqName: fileName:/forWithBreakContinue.kt CALL 'public abstract fun iterator (): kotlin.collections.Iterator> declared in kotlin.collections.List' type=kotlin.collections.Iterator> origin=null WHILE label=null origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null VAR name:s type:T of [val] CALL 'public abstract fun next (): T of declared in kotlin.collections.Iterator' type=T of origin=null BREAK label=null loop.label=null @@ -21,7 +21,7 @@ FILE fqName: fileName:/forWithBreakContinue.kt CALL 'public abstract fun iterator (): kotlin.collections.Iterator> declared in kotlin.collections.List' type=kotlin.collections.Iterator> origin=null WHILE label=OUTER origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null VAR name:s1 type:T of [val] CALL 'public abstract fun next (): T of declared in kotlin.collections.Iterator' type=T of origin=null VAR name: type:kotlin.collections.List [val] @@ -30,7 +30,7 @@ FILE fqName: fileName:/forWithBreakContinue.kt CALL 'public abstract fun iterator (): kotlin.collections.Iterator> declared in kotlin.collections.List' type=kotlin.collections.Iterator> origin=null WHILE label=INNER origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null VAR name:s2 type:T of [val] CALL 'public abstract fun next (): T of declared in kotlin.collections.Iterator' type=T of origin=null BREAK label=OUTER loop.label=OUTER @@ -46,7 +46,7 @@ FILE fqName: fileName:/forWithBreakContinue.kt CALL 'public abstract fun iterator (): kotlin.collections.Iterator> declared in kotlin.collections.List' type=kotlin.collections.Iterator> origin=null WHILE label=null origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null VAR name:s type:T of [val] CALL 'public abstract fun next (): T of declared in kotlin.collections.Iterator' type=T of origin=null CONTINUE label=null loop.label=null @@ -59,7 +59,7 @@ FILE fqName: fileName:/forWithBreakContinue.kt CALL 'public abstract fun iterator (): kotlin.collections.Iterator> declared in kotlin.collections.List' type=kotlin.collections.Iterator> origin=null WHILE label=OUTER origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null VAR name:s1 type:T of [val] CALL 'public abstract fun next (): T of declared in kotlin.collections.Iterator' type=T of origin=null VAR name: type:kotlin.collections.List [val] @@ -68,7 +68,7 @@ FILE fqName: fileName:/forWithBreakContinue.kt CALL 'public abstract fun iterator (): kotlin.collections.Iterator> declared in kotlin.collections.List' type=kotlin.collections.Iterator> origin=null WHILE label=INNER origin=FOR_LOOP_INNER_WHILE condition: CALL 'public abstract fun hasNext (): kotlin.Boolean declared in kotlin.collections.Iterator' type=kotlin.Boolean origin=null - body: BLOCK type=IrErrorType origin=null + body: BLOCK type=kotlin.Nothing origin=null VAR name:s2 type:T of [val] CALL 'public abstract fun next (): T of declared in kotlin.collections.Iterator' type=T of origin=null CONTINUE label=OUTER loop.label=OUTER