From 22aa9ee65f759ad21aeaeb8ad9ac0b123b2c32fe Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Wed, 13 Dec 2023 22:34:39 +0100 Subject: [PATCH] IR text tests: Unmute tests with frontend errors --- .../expressions/badBreakContinue.fir.ir.txt | 31 ++ .../expressions/badBreakContinue.fir.kt.txt | 28 ++ .../ir/irText/expressions/badBreakContinue.kt | 10 +- .../badInlinedBreakContinue.fir.ir.txt | 372 ++++++++++++++++++ .../badInlinedBreakContinue.fir.kt.txt | 243 ++++++++++++ .../expressions/badInlinedBreakContinue.kt | 16 +- 6 files changed, 688 insertions(+), 12 deletions(-) create mode 100644 compiler/testData/ir/irText/expressions/badBreakContinue.fir.ir.txt create mode 100644 compiler/testData/ir/irText/expressions/badBreakContinue.fir.kt.txt create mode 100644 compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.ir.txt create mode 100644 compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.kt.txt diff --git a/compiler/testData/ir/irText/expressions/badBreakContinue.fir.ir.txt b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.ir.txt new file mode 100644 index 00000000000..dfded68caa5 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.ir.txt @@ -0,0 +1,31 @@ +FILE fqName: fileName:/badBreakContinue.kt + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + WHILE label=L1 origin=WHILE_LOOP + condition: CONST Boolean type=kotlin.Boolean value=true + body: BLOCK type=kotlin.Unit 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 + BLOCK_BODY + WHILE label=L1 origin=WHILE_LOOP + condition: CONST Boolean type=kotlin.Boolean value=true + body: BLOCK type=kotlin.Unit origin=null + VAR name:lambda type:kotlin.Function0 [val] + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing + BLOCK_BODY + BREAK label=L1 loop.label=L1 + CONTINUE label=L1 loop.label=L1 + FUN name:test4 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + WHILE label=null origin=WHILE_LOOP + condition: ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null diff --git a/compiler/testData/ir/irText/expressions/badBreakContinue.fir.kt.txt b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.kt.txt new file mode 100644 index 00000000000..4179b45477d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/badBreakContinue.fir.kt.txt @@ -0,0 +1,28 @@ +fun test1() { + error("") /* ErrorExpression */ + error("") /* ErrorExpression */ +} + +fun test2() { + L1@ while (true) { // BLOCK + error("") /* ErrorExpression */ + error("") /* ErrorExpression */ + } +} + +fun test3() { + L1@ while (true) { // BLOCK + val lambda: Function0 = local fun (): Nothing { + break@L1 + continue@L1 + } + + } +} + +fun test4() { + while (error("") /* ErrorExpression */) { // BLOCK + } + while (error("") /* ErrorExpression */) { // BLOCK + } +} diff --git a/compiler/testData/ir/irText/expressions/badBreakContinue.kt b/compiler/testData/ir/irText/expressions/badBreakContinue.kt index ceb838beb00..c04f8c791e5 100644 --- a/compiler/testData/ir/irText/expressions/badBreakContinue.kt +++ b/compiler/testData/ir/irText/expressions/badBreakContinue.kt @@ -1,10 +1,8 @@ -// IGNORE_BACKEND_K2: JVM_IR -// IGNORE_BACKEND: JS_IR -// !IGNORE_ERRORS +// IGNORE_ERRORS +// IGNORE_FIR_DIAGNOSTICS // DIAGNOSTICS: -BREAK_OR_CONTINUE_OUTSIDE_A_LOOP -NOT_A_LOOP_LABEL -UNRESOLVED_REFERENCE -BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY - -// KT-61141: java.lang.RuntimeException: Loop not found for break expression: break -// IGNORE_BACKEND: NATIVE +// ERROR_POLICY: SEMANTIC +// SKIP_KLIB_TEST fun test1() { break diff --git a/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.ir.txt b/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.ir.txt new file mode 100644 index 00000000000..620bd21c3fa --- /dev/null +++ b/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.ir.txt @@ -0,0 +1,372 @@ +FILE fqName: fileName:/badInlinedBreakContinue.kt + FUN name:foo visibility:public modality:FINAL <> (block:kotlin.Function0) returnType:kotlin.Unit [inline] + VALUE_PARAMETER name:block index:0 type:kotlin.Function0 + BLOCK_BODY + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'block: kotlin.Function0 declared in .foo' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + FUN name:bar visibility:public modality:FINAL <> (block1:kotlin.Function0, block2:kotlin.Function0) returnType:kotlin.Unit [inline] + VALUE_PARAMETER name:block1 index:0 type:kotlin.Function0 + VALUE_PARAMETER name:block2 index:1 type:kotlin.Function0 [noinline] + BLOCK_BODY + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'block1: kotlin.Function0 declared in .bar' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'block2: kotlin.Function0 declared in .bar' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + FUN name:baz visibility:public modality:FINAL <> (block:kotlin.Function0) returnType:kotlin.Unit [inline] + VALUE_PARAMETER name:block index:0 type:kotlin.Function0 [crossinline] + BLOCK_BODY + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'block: kotlin.Function0 declared in .baz' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + FUN name:myForEach visibility:public modality:FINAL ($receiver:kotlin.collections.Iterable.myForEach>, action:kotlin.Function1.myForEach, kotlin.Unit>) returnType:kotlin.Unit [inline] + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + $receiver: VALUE_PARAMETER name: type:kotlin.collections.Iterable.myForEach> + VALUE_PARAMETER name:action index:0 type:kotlin.Function1.myForEach, kotlin.Unit> + BLOCK_BODY + BLOCK type=kotlin.Unit origin=FOR_LOOP + VAR FOR_LOOP_ITERATOR name:tmp_0 type:kotlin.collections.Iterator.myForEach> [val] + CALL 'public abstract fun iterator (): kotlin.collections.Iterator declared in kotlin.collections.Iterable' type=kotlin.collections.Iterator.myForEach> origin=FOR_LOOP_ITERATOR + $this: GET_VAR ': kotlin.collections.Iterable.myForEach> declared in .myForEach' type=kotlin.collections.Iterable.myForEach> 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=FOR_LOOP_HAS_NEXT + $this: GET_VAR 'val tmp_0: kotlin.collections.Iterator.myForEach> declared in .myForEach' type=kotlin.collections.Iterator.myForEach> origin=null + body: BLOCK type=kotlin.Unit origin=FOR_LOOP_INNER_WHILE + VAR FOR_LOOP_VARIABLE name:element type:T of .myForEach [val] + CALL 'public abstract fun next (): T of kotlin.collections.Iterator declared in kotlin.collections.Iterator' type=T of .myForEach origin=FOR_LOOP_NEXT + $this: GET_VAR 'val tmp_0: kotlin.collections.Iterator.myForEach> declared in .myForEach' type=kotlin.collections.Iterator.myForEach> origin=null + CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 declared in kotlin.Function1' type=kotlin.Unit origin=INVOKE + $this: GET_VAR 'action: kotlin.Function1.myForEach, kotlin.Unit> declared in .myForEach' type=kotlin.Function1.myForEach, kotlin.Unit> origin=VARIABLE_AS_FUNCTION + p1: GET_VAR 'val element: T of .myForEach declared in .myForEach' type=T of .myForEach origin=null + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun invoke (value: T of kotlin.invoke): R of kotlin.invoke declared in kotlin' type=IrErrorType(null) origin=null + : IrErrorType(null) + : IrErrorType(null) + $receiver: ERROR_CALL 'Cannot bind 1 arguments to kotlin/Function0.invoke|invoke(){}[0] call with 0 parameters' type=kotlin.Nothing + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + WHILE label=L1 origin=WHILE_LOOP + condition: CONST Boolean type=kotlin.Boolean value=true + body: BLOCK type=kotlin.Unit origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun invoke (value: T of kotlin.invoke): R of kotlin.invoke declared in kotlin' type=IrErrorType(null) origin=null + : IrErrorType(null) + : IrErrorType(null) + $receiver: ERROR_CALL 'Cannot bind 1 arguments to kotlin/Function0.invoke|invoke(){}[0] call with 0 parameters' type=kotlin.Nothing + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind label ERROR to a loop)] ' type=kotlin.Nothing + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + 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 + BLOCK_BODY + WHILE label=L1 origin=WHILE_LOOP + condition: CONST Boolean type=kotlin.Boolean value=true + body: BLOCK type=kotlin.Unit origin=null + VAR name:lambda type:kotlin.Function0 [val] + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun invoke (value: T of kotlin.invoke): R of kotlin.invoke declared in kotlin' type=IrErrorType(null) origin=null + : IrErrorType(null) + : IrErrorType(null) + $receiver: ERROR_CALL 'Cannot bind 1 arguments to kotlin/Function0.invoke|invoke(){}[0] call with 0 parameters' type=kotlin.Nothing + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing + BLOCK_BODY + CONTINUE label=L1 loop.label=L1 + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BREAK label=L1 loop.label=L1 + CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CONTINUE label=L1 loop.label=L1 + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BREAK label=L1 loop.label=L1 + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CONTINUE label=L1 loop.label=L1 + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BREAK label=L1 loop.label=L1 + CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CONTINUE label=L1 loop.label=L1 + FUN name:test4 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Nothing origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Nothing origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Nothing + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public abstract fun invoke (): R of kotlin.Function0 declared in kotlin.Function0' type=kotlin.Unit origin=INVOKE + $this: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + WHILE label=null origin=WHILE_LOOP + condition: CALL 'public final fun foo (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + body: BLOCK type=kotlin.Unit origin=null + FUN name:test5 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun forEach (action: kotlin.Function1): kotlin.Unit declared in kotlin.collections' type=kotlin.Unit origin=null + : kotlin.Int + $receiver: CALL 'public final fun listOf (vararg elements: T of kotlin.collections.listOf): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null + : kotlin.Int + elements: VARARG type=kotlin.Array varargElementType=kotlin.Int + CONST Int type=kotlin.Int value=1 + CONST Int type=kotlin.Int value=2 + CONST Int type=kotlin.Int value=3 + action: FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:i index:0 type:kotlin.Int + BLOCK_BODY + 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 'i: kotlin.Int declared in .test5.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=2 + then: ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public final fun forEach (action: kotlin.Function1): kotlin.Unit declared in kotlin.collections' type=kotlin.Unit origin=null + : kotlin.Int + $receiver: CALL 'public final fun listOf (vararg elements: T of kotlin.collections.listOf): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null + : kotlin.Int + elements: VARARG type=kotlin.Array varargElementType=kotlin.Int + CONST Int type=kotlin.Int value=1 + CONST Int type=kotlin.Int value=2 + CONST Int type=kotlin.Int value=3 + action: FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:i index:0 type:kotlin.Int + BLOCK_BODY + 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 'i: kotlin.Int declared in .test5.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=2 + then: ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public final fun forEach (action: kotlin.Function1): kotlin.Unit declared in kotlin.collections' type=kotlin.Unit origin=null + : kotlin.Int + $receiver: CALL 'public final fun listOf (vararg elements: T of kotlin.collections.listOf): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null + : kotlin.Int + elements: VARARG type=kotlin.Array varargElementType=kotlin.Int + CONST Int type=kotlin.Int value=1 + CONST Int type=kotlin.Int value=2 + CONST Int type=kotlin.Int value=3 + action: FUN_EXPR type=kotlin.Function1 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:i index:0 type:kotlin.Int + BLOCK_BODY + 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 'i: kotlin.Int declared in .test5.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=2 + then: ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + CALL 'public final fun forEach (action: kotlin.Function1): kotlin.Unit declared in kotlin.collections' type=kotlin.Unit origin=null + : kotlin.Int + $receiver: CALL 'public final fun listOf (vararg elements: T of kotlin.collections.listOf): kotlin.collections.List declared in kotlin.collections' type=kotlin.collections.List origin=null + : kotlin.Int + elements: VARARG type=kotlin.Array varargElementType=kotlin.Int + CONST Int type=kotlin.Int value=1 + CONST Int type=kotlin.Int value=2 + CONST Int type=kotlin.Int value=3 + action: FUN_EXPR type=kotlin.Function1 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:i index:0 type:kotlin.Int + BLOCK_BODY + 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 'i: kotlin.Int declared in .test5.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=2 + then: ERROR_EXPR 'Unbound loop: continue@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + FUN name:test6 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + WHILE label=null origin=WHILE_LOOP + condition: CONST Boolean type=kotlin.Boolean value=true + body: BLOCK type=kotlin.Unit origin=null + CALL 'public final fun bar (block1: kotlin.Function0, block2: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block1: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test6' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + block2: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BREAK label=null loop.label=null + CALL 'public final fun bar (block1: kotlin.Function0, block2: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block1: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Unit declared in .test6' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit + block2: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CONTINUE label=null loop.label=null + CALL 'public final fun bar (block1: kotlin.Function0, block2: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block1: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + block2: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BREAK label=null loop.label=null + CALL 'public final fun bar (block1: kotlin.Function0, block2: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block1: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + block2: FUN_EXPR type=kotlin.Function0 origin=ANONYMOUS_FUNCTION + FUN LOCAL_FUNCTION name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CONTINUE label=null loop.label=null + FUN name:test7 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun myForEach (action: kotlin.Function1.myForEach, kotlin.Unit>): kotlin.Unit declared in ' type=kotlin.Unit origin=null + : kotlin.Int + $receiver: CALL 'public final fun rangeTo (other: kotlin.Int): kotlin.ranges.IntRange declared in kotlin.Int' type=kotlin.ranges.IntRange origin=RANGE + $this: CONST Int type=kotlin.Int value=1 + other: CONST Int type=kotlin.Int value=3 + action: FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (i:kotlin.Int) returnType:kotlin.Unit + VALUE_PARAMETER name:i index:0 type:kotlin.Int + BLOCK_BODY + 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 'i: kotlin.Int declared in .test7.' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=2 + then: BLOCK type=kotlin.Unit origin=null + ERROR_EXPR 'Unbound loop: break@@@[ERROR_EXPR(Cannot bind unlabeled jump to a loop)] ' type=kotlin.Nothing + FUN name:test8 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + WHILE label=null origin=WHILE_LOOP + condition: CONST Boolean type=kotlin.Boolean value=true + body: BLOCK type=kotlin.Unit origin=null + CALL 'public final fun baz (block: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + BREAK label=null loop.label=null diff --git a/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.kt.txt b/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.kt.txt new file mode 100644 index 00000000000..848d09cab0d --- /dev/null +++ b/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.fir.kt.txt @@ -0,0 +1,243 @@ +inline fun foo(block: Function0) { + block.invoke() +} + +inline fun bar(block1: Function0, noinline block2: Function0) { + block1.invoke() + block2.invoke() +} + +inline fun baz(crossinline block: Function0) { + block.invoke() +} + +inline fun Iterable.myForEach(action: Function1) { + { // BLOCK + val tmp_0: Iterator = .iterator() + while (tmp_0.hasNext()) { // BLOCK + val element: T = tmp_0.next() + action.invoke(p1 = element) + } + } +} + +fun test1() { + error("") /* ErrorCallExpression */local fun (): Nothing { + error("") /* ErrorExpression */ + } +; .invoke() /*~> Unit */ + local fun () { + error("") /* ErrorExpression */ + } +.invoke() + local fun () { + error("") /* ErrorExpression */ + } +.invoke() + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) +} + +fun test2() { + L1@ while (true) { // BLOCK + error("") /* ErrorCallExpression */local fun (): Nothing { + error("") /* ErrorExpression */ + } +; .invoke() /*~> Unit */ + local fun () { + error("") /* ErrorExpression */ + } +.invoke() + local fun () { + error("") /* ErrorExpression */ + } +.invoke() + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) + foo(block = local fun () { + error("") /* ErrorExpression */ + } +) + } +} + +fun test3() { + L1@ while (true) { // BLOCK + val lambda: Function0 = local fun () { + error("") /* ErrorCallExpression */local fun (): Nothing { + continue@L1 + } +; .invoke() /*~> Unit */ + local fun () { + break@L1 + } +.invoke() + local fun () { + continue@L1 + } +.invoke() + foo(block = local fun () { + break@L1 + } +) + foo(block = local fun () { + continue@L1 + } +) + foo(block = local fun () { + break@L1 + } +) + foo(block = local fun () { + continue@L1 + } +) + } + + } +} + +fun test4() { + while (local fun (): Nothing { + error("") /* ErrorExpression */ + } +.invoke()) { // BLOCK + } + while (local fun (): Nothing { + error("") /* ErrorExpression */ + } +.invoke()) { // BLOCK + } + while (local fun () { + error("") /* ErrorExpression */ + } +.invoke()) { // BLOCK + } + while (local fun () { + error("") /* ErrorExpression */ + } +.invoke()) { // BLOCK + } + while (foo(block = local fun () { + error("") /* ErrorExpression */ + } +)) { // BLOCK + } + while (foo(block = local fun () { + error("") /* ErrorExpression */ + } +)) { // BLOCK + } + while (foo(block = local fun () { + error("") /* ErrorExpression */ + } +)) { // BLOCK + } + while (foo(block = local fun () { + error("") /* ErrorExpression */ + } +)) { // BLOCK + } +} + +fun test5() { + listOf(elements = [1, 2, 3]).forEach(action = local fun (i: Int) { + when { + EQEQ(arg0 = i, arg1 = 2) -> error("") /* ErrorExpression */ + } + } +) + listOf(elements = [1, 2, 3]).forEach(action = local fun (i: Int) { + when { + EQEQ(arg0 = i, arg1 = 2) -> error("") /* ErrorExpression */ + } + } +) + listOf(elements = [1, 2, 3]).forEach(action = local fun (i: Int) { + when { + EQEQ(arg0 = i, arg1 = 2) -> error("") /* ErrorExpression */ + } + } +) + listOf(elements = [1, 2, 3]).forEach(action = local fun (i: Int) { + when { + EQEQ(arg0 = i, arg1 = 2) -> error("") /* ErrorExpression */ + } + } +) +} + +fun test6() { + while (true) { // BLOCK + bar(block1 = local fun () { + return Unit + } +, block2 = local fun () { + break + } +) + bar(block1 = local fun () { + return Unit + } +, block2 = local fun () { + continue + } +) + bar(block1 = local fun () { + } +, block2 = local fun () { + break + } +) + bar(block1 = local fun () { + } +, block2 = local fun () { + continue + } +) + } +} + +fun test7() { + 1.rangeTo(other = 3).myForEach(action = local fun (i: Int) { + when { + EQEQ(arg0 = i, arg1 = 2) -> { // BLOCK + error("") /* ErrorExpression */ + } + } + } +) +} + +fun test8() { + while (true) { // BLOCK + baz(block = local fun () { + break + } +) + } +} diff --git a/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.kt b/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.kt index 42059c7743d..e5c98dcac31 100644 --- a/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.kt +++ b/compiler/testData/ir/irText/expressions/badInlinedBreakContinue.kt @@ -1,12 +1,16 @@ +// IGNORE_ERRORS +// IGNORE_FIR_DIAGNOSTICS +// DIAGNOSTICS: -NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER -BREAK_OR_CONTINUE_OUTSIDE_A_LOOP -UNEXPECTED_TRAILING_LAMBDA_ON_A_NEW_LINE -NO_VALUE_FOR_PARAMETER -NOT_A_LOOP_LABEL -UNRESOLVED_REFERENCE -TYPE_MISMATCH -BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY -TOO_MANY_ARGUMENTS -CONDITION_TYPE_MISMATCH +// ERROR_POLICY: SEMANTIC // LANGUAGE: +BreakContinueInInlineLambdas -// IGNORE_BACKEND_K2: JVM_IR -// IGNORE_BACKEND: JS_IR -// !IGNORE_ERRORS -// DIAGNOSTICS: -NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER -BREAK_OR_CONTINUE_OUTSIDE_A_LOOP -UNEXPECTED_TRAILING_LAMBDA_ON_A_NEW_LINE -NO_VALUE_FOR_PARAMETER -NOT_A_LOOP_LABEL -UNRESOLVED_REFERENCE -TYPE_MISMATCH -BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY // WITH_STDLIB +// SKIP_KLIB_TEST -// KT-61141: NPE at org.jetbrains.kotlin.psi2ir.generators.ArgumentsGenerationUtilsKt.pregenerateValueArgumentsUsing() -// IGNORE_BACKEND: NATIVE +// IGNORE_BACKEND_K2: JVM_IR +// ^^^ The IrErrorCallExpression inside the body of test1() function is dumped in a different way on JVM K1 and JVM K2. +// That is because `IrErrorCallExpression.description` includes a signature of a local lambda, which is mangled +// differently on K1 and K2. This is not a problem since signatures for local entities do not participate in IR-linkage. +// But the test needs to be muted. inline fun foo(block: () -> Unit) { block() }