FIR: implement trivial typing for break & continue

This commit is contained in:
Mikhail Glukhikh
2019-04-11 16:56:19 +03:00
parent b9f09afc6f
commit 618295f505
5 changed files with 24 additions and 21 deletions
@@ -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<FirLoop> {
override lateinit var target: FirTarget<FirLoop>
override var typeRef: FirTypeRef = FirImplicitNothingTypeRef(session, psi)
}
@@ -7,7 +7,7 @@ FILE fqName:<root> 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:<root> fileName:/badBreakContinue.kt
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:IrErrorType
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <anonymous> (): IrErrorType declared in <root>.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 <anonymous> (): IrErrorType declared in <root>.test3' type=IrErrorType origin=LAMBDA
@@ -17,19 +17,19 @@ FILE fqName:<root> 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:<root> 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
@@ -45,11 +45,11 @@ FILE fqName:<root> 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:<range> type:IrErrorType [val]
BLOCK type=IrErrorType origin=ELVIS
VAR name:<range> type:kotlin.Nothing [val]
BLOCK type=kotlin.Nothing origin=ELVIS
VAR name:<elvis> type:kotlin.collections.List<kotlin.String>? [val]
GET_VAR 'ss: kotlin.collections.List<kotlin.String>? declared in <root>.test3' type=kotlin.collections.List<kotlin.String>? 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 <elvis>: kotlin.collections.List<kotlin.String>? [val] declared in <root>.test3' type=kotlin.collections.List<kotlin.String>? origin=null
@@ -71,11 +71,11 @@ FILE fqName:<root> 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:<range> type:IrErrorType [val]
BLOCK type=IrErrorType origin=ELVIS
VAR name:<range> type:kotlin.Nothing [val]
BLOCK type=kotlin.Nothing origin=ELVIS
VAR name:<elvis> type:kotlin.collections.List<kotlin.String>? [val]
GET_VAR 'ss: kotlin.collections.List<kotlin.String>? declared in <root>.test4' type=kotlin.collections.List<kotlin.String>? 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 <elvis>: kotlin.collections.List<kotlin.String>? [val] declared in <root>.test4' type=kotlin.collections.List<kotlin.String>? origin=null
@@ -8,7 +8,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of <uninitialized parent>> declared in kotlin.collections.List' type=kotlin.collections.Iterator<E of <uninitialized parent>> 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 <uninitialized parent> [val]
CALL 'public abstract fun next (): T of <uninitialized parent> declared in kotlin.collections.Iterator' type=T of <uninitialized parent> origin=null
BREAK label=null loop.label=null
@@ -21,7 +21,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of <uninitialized parent>> declared in kotlin.collections.List' type=kotlin.collections.Iterator<E of <uninitialized parent>> 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 <uninitialized parent> [val]
CALL 'public abstract fun next (): T of <uninitialized parent> declared in kotlin.collections.Iterator' type=T of <uninitialized parent> origin=null
VAR name:<range> type:kotlin.collections.List<kotlin.String> [val]
@@ -30,7 +30,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of <uninitialized parent>> declared in kotlin.collections.List' type=kotlin.collections.Iterator<E of <uninitialized parent>> 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 <uninitialized parent> [val]
CALL 'public abstract fun next (): T of <uninitialized parent> declared in kotlin.collections.Iterator' type=T of <uninitialized parent> origin=null
BREAK label=OUTER loop.label=OUTER
@@ -46,7 +46,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of <uninitialized parent>> declared in kotlin.collections.List' type=kotlin.collections.Iterator<E of <uninitialized parent>> 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 <uninitialized parent> [val]
CALL 'public abstract fun next (): T of <uninitialized parent> declared in kotlin.collections.Iterator' type=T of <uninitialized parent> origin=null
CONTINUE label=null loop.label=null
@@ -59,7 +59,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of <uninitialized parent>> declared in kotlin.collections.List' type=kotlin.collections.Iterator<E of <uninitialized parent>> 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 <uninitialized parent> [val]
CALL 'public abstract fun next (): T of <uninitialized parent> declared in kotlin.collections.Iterator' type=T of <uninitialized parent> origin=null
VAR name:<range> type:kotlin.collections.List<kotlin.String> [val]
@@ -68,7 +68,7 @@ FILE fqName:<root> fileName:/forWithBreakContinue.kt
CALL 'public abstract fun iterator (): kotlin.collections.Iterator<E of <uninitialized parent>> declared in kotlin.collections.List' type=kotlin.collections.Iterator<E of <uninitialized parent>> 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 <uninitialized parent> [val]
CALL 'public abstract fun next (): T of <uninitialized parent> declared in kotlin.collections.Iterator' type=T of <uninitialized parent> origin=null
CONTINUE label=OUTER loop.label=OUTER