Fix of getCorrespondingLoop for complex loop / try-finally trees #KT-8246 Fixed
This commit is contained in:
@@ -793,16 +793,31 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
|||||||
override fun visitBreakExpression(expression: KtBreakExpression) {
|
override fun visitBreakExpression(expression: KtBreakExpression) {
|
||||||
val loop = getCorrespondingLoop(expression)
|
val loop = getCorrespondingLoop(expression)
|
||||||
if (loop != null) {
|
if (loop != null) {
|
||||||
checkJumpDoesNotCrossFunctionBoundary(expression, loop)
|
if (jumpDoesNotCrossFunctionBoundary(expression, loop)) {
|
||||||
builder.getExitPoint(loop)?.let { builder.jump(it, expression) }
|
builder.getExitPoint(loop)?.let { builder.jump(it, expression) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitContinueExpression(expression: KtContinueExpression) {
|
override fun visitContinueExpression(expression: KtContinueExpression) {
|
||||||
val loop = getCorrespondingLoop(expression)
|
val loop = getCorrespondingLoop(expression)
|
||||||
if (loop != null) {
|
if (loop != null) {
|
||||||
checkJumpDoesNotCrossFunctionBoundary(expression, loop)
|
if (jumpDoesNotCrossFunctionBoundary(expression, loop)) {
|
||||||
builder.jump(builder.getConditionEntryPoint(loop), expression)
|
builder.jump(builder.getConditionEntryPoint(loop), expression)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getNearestLoopExpression(expression: KtExpression) = expression.getStrictParentOfType<KtLoopExpression>()
|
||||||
|
|
||||||
|
private fun getCorrespondingLoopWithoutLabel(expression: KtExpression): KtLoopExpression? {
|
||||||
|
val parentLoop = getNearestLoopExpression(expression) ?: return null
|
||||||
|
val parentBody = parentLoop.body
|
||||||
|
return if (parentBody != null && parentBody.textRange.contains(expression.textRange)) {
|
||||||
|
parentLoop
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
getNearestLoopExpression(parentLoop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,7 +836,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
loop = builder.currentLoop
|
loop = getCorrespondingLoopWithoutLabel(expression)
|
||||||
if (loop == null) {
|
if (loop == null) {
|
||||||
trace.report(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP.on(expression))
|
trace.report(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP.on(expression))
|
||||||
}
|
}
|
||||||
@@ -842,13 +857,24 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
|||||||
return loop
|
return loop
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkJumpDoesNotCrossFunctionBoundary(jumpExpression: KtExpressionWithLabel, jumpTarget: KtElement) {
|
private fun jumpDoesNotCrossFunctionBoundary(jumpExpression: KtExpressionWithLabel, jumpTarget: KtElement): Boolean {
|
||||||
val bindingContext = trace.bindingContext
|
val bindingContext = trace.bindingContext
|
||||||
|
|
||||||
val labelExprEnclosingFunc = BindingContextUtils.getEnclosingFunctionDescriptor(bindingContext, jumpExpression)
|
val labelExprEnclosingFunc = BindingContextUtils.getEnclosingFunctionDescriptor(bindingContext, jumpExpression)
|
||||||
val labelTargetEnclosingFunc = BindingContextUtils.getEnclosingFunctionDescriptor(bindingContext, jumpTarget)
|
val labelTargetEnclosingFunc = BindingContextUtils.getEnclosingFunctionDescriptor(bindingContext, jumpTarget)
|
||||||
if (labelExprEnclosingFunc !== labelTargetEnclosingFunc) {
|
return if (labelExprEnclosingFunc !== labelTargetEnclosingFunc) {
|
||||||
trace.report(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY.on(jumpExpression))
|
// Check to report only once
|
||||||
|
if (builder.getExitPoint(jumpTarget) != null ||
|
||||||
|
// Local class secondary constructors are handled differently
|
||||||
|
// They are the only local class element NOT included in owner pseudocode
|
||||||
|
// See generateInitializersForScriptClassOrObject && generateDeclarationForLocalClassOrObjectIfNeeded
|
||||||
|
labelExprEnclosingFunc is ConstructorDescriptor && !labelExprEnclosingFunc.isPrimary) {
|
||||||
|
trace.report(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY.on(jumpExpression))
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -470,7 +470,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter");
|
MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter");
|
||||||
MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop");
|
MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop");
|
||||||
MAP.put(BREAK_OR_CONTINUE_IN_WHEN, "'break' and 'continue' are not allowed in 'when' statements. Consider using labels to continue/break from the outer loop");
|
MAP.put(BREAK_OR_CONTINUE_IN_WHEN, "'break' and 'continue' are not allowed in 'when' statements. Consider using labels to continue/break from the outer loop");
|
||||||
MAP.put(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY, "'break' or 'continue' jumps across a function boundary");
|
MAP.put(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY, "'break' or 'continue' jumps across a function or a class boundary");
|
||||||
MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", STRING);
|
MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", STRING);
|
||||||
MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", STRING);
|
MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", STRING);
|
||||||
|
|
||||||
|
|||||||
@@ -125,9 +125,18 @@ public class BindingContextUtils {
|
|||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static FunctionDescriptor getEnclosingFunctionDescriptor(@NotNull BindingContext context, @NotNull KtElement element) {
|
public static FunctionDescriptor getEnclosingFunctionDescriptor(@NotNull BindingContext context, @NotNull KtElement element) {
|
||||||
KtFunction function = PsiTreeUtil.getParentOfType(element, KtFunction.class);
|
KtElement functionOrClass = PsiTreeUtil.getParentOfType(element, KtFunction.class, KtClassOrObject.class);
|
||||||
return (FunctionDescriptor)context.get(DECLARATION_TO_DESCRIPTOR, function);
|
DeclarationDescriptor descriptor = context.get(DECLARATION_TO_DESCRIPTOR, functionOrClass);
|
||||||
|
if (functionOrClass instanceof KtFunction) {
|
||||||
|
if (descriptor instanceof FunctionDescriptor) return (FunctionDescriptor) descriptor;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (descriptor instanceof ClassDescriptor) return ((ClassDescriptor) descriptor).getUnsubstitutedPrimaryConstructor();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reportAmbiguousLabel(
|
public static void reportAmbiguousLabel(
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ L7 [after local declaration]:
|
|||||||
3 jmp(L2) NEXT:[jmp?(L3)]
|
3 jmp(L2) NEXT:[jmp?(L3)]
|
||||||
L3 [loop exit point]:
|
L3 [loop exit point]:
|
||||||
L5 [body exit point]:
|
L5 [body exit point]:
|
||||||
read (Unit) PREV:[jmp?(L3), jmp(L3)]
|
read (Unit) PREV:[jmp?(L3)]
|
||||||
L1:
|
L1:
|
||||||
1 <END> NEXT:[<SINK>]
|
1 <END> NEXT:[<SINK>]
|
||||||
error:
|
error:
|
||||||
@@ -47,12 +47,11 @@ sink:
|
|||||||
L8:
|
L8:
|
||||||
5 <START>
|
5 <START>
|
||||||
6 mark(break)
|
6 mark(break)
|
||||||
jmp(L3) NEXT:[read (Unit)]
|
5 ret(*|!<v0>) L9
|
||||||
- 5 ret(*|!<v0>) L9 PREV:[]
|
|
||||||
L9:
|
L9:
|
||||||
<END> NEXT:[<SINK>] PREV:[]
|
<END> NEXT:[<SINK>]
|
||||||
error:
|
error:
|
||||||
<ERROR> PREV:[]
|
<ERROR> PREV:[]
|
||||||
sink:
|
sink:
|
||||||
<SINK> PREV:[<ERROR>, <END>]
|
<SINK> PREV:[<ERROR>, <END>]
|
||||||
=====================
|
=====================
|
||||||
|
|||||||
+137
@@ -0,0 +1,137 @@
|
|||||||
|
== foo ==
|
||||||
|
fun foo() {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
continue@outer
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("OK")
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
L0:
|
||||||
|
1 <START>
|
||||||
|
2 mark({ outer@while (true) { try { while (true) { continue@outer } } finally { break } } println("OK") })
|
||||||
|
mark(outer@while (true) { try { while (true) { continue@outer } } finally { break } })
|
||||||
|
L2 [loop entry point]:
|
||||||
|
L6 [condition entry point]:
|
||||||
|
r(true) -> <v0>
|
||||||
|
mark(while (true) { try { while (true) { continue@outer } } finally { break } })
|
||||||
|
magic[VALUE_CONSUMER](true|<v0>) -> <v1>
|
||||||
|
L4 [body entry point]:
|
||||||
|
3 mark({ try { while (true) { continue@outer } } finally { break } })
|
||||||
|
mark(try { while (true) { continue@outer } } finally { break })
|
||||||
|
jmp?(L7) NEXT:[mark({ break }), mark({ while (true) { continue@outer } })]
|
||||||
|
4 mark({ while (true) { continue@outer } })
|
||||||
|
L8 [loop entry point]:
|
||||||
|
L12 [condition entry point]:
|
||||||
|
r(true) -> <v2>
|
||||||
|
mark(while (true) { continue@outer })
|
||||||
|
magic[VALUE_CONSUMER](true|<v2>) -> <v3>
|
||||||
|
L10 [body entry point]:
|
||||||
|
5 mark({ continue@outer })
|
||||||
|
L13 [start finally]:
|
||||||
|
6 mark({ break })
|
||||||
|
jmp(L3) NEXT:[read (Unit)]
|
||||||
|
L14 [finish finally]:
|
||||||
|
- 5 jmp(L6) NEXT:[r(true) -> <v0>] PREV:[]
|
||||||
|
- 4 jmp(L8) NEXT:[r(true) -> <v2>] PREV:[]
|
||||||
|
L9 [loop exit point]:
|
||||||
|
L11 [body exit point]:
|
||||||
|
- read (Unit) PREV:[]
|
||||||
|
- 3 jmp(L15) NEXT:[mark({ break })] PREV:[]
|
||||||
|
L7 [onExceptionToFinallyBlock]:
|
||||||
|
6 mark({ break }) PREV:[jmp?(L7)]
|
||||||
|
jmp(L3) NEXT:[read (Unit)]
|
||||||
|
- 3 jmp(error) NEXT:[<ERROR>] PREV:[]
|
||||||
|
L15 [skipFinallyToErrorBlock]:
|
||||||
|
- 6 mark({ break }) PREV:[]
|
||||||
|
- jmp(L3) NEXT:[read (Unit)] PREV:[]
|
||||||
|
- 3 merge(try { while (true) { continue@outer } } finally { break }|!<v6>) -> <v7> PREV:[]
|
||||||
|
- 2 jmp(L2) NEXT:[r(true) -> <v0>] PREV:[]
|
||||||
|
L3 [loop exit point]:
|
||||||
|
L5 [body exit point]:
|
||||||
|
read (Unit) PREV:[jmp(L3), jmp(L3)]
|
||||||
|
mark("OK")
|
||||||
|
r("OK") -> <v9>
|
||||||
|
mark(println("OK"))
|
||||||
|
magic[UNRESOLVED_CALL](println("OK")|<v9>, !<v10>) -> <v11>
|
||||||
|
L1:
|
||||||
|
1 <END> NEXT:[<SINK>]
|
||||||
|
error:
|
||||||
|
<ERROR> PREV:[]
|
||||||
|
sink:
|
||||||
|
<SINK> PREV:[<ERROR>, <END>]
|
||||||
|
=====================
|
||||||
|
== bar ==
|
||||||
|
fun bar(): String {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
continue@outer
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
L0:
|
||||||
|
1 <START>
|
||||||
|
2 mark({ outer@while (true) { try { while (true) { continue@outer } } finally { return "OK" } } })
|
||||||
|
mark(outer@while (true) { try { while (true) { continue@outer } } finally { return "OK" } })
|
||||||
|
L2 [loop entry point]:
|
||||||
|
L6 [condition entry point]:
|
||||||
|
r(true) -> <v0>
|
||||||
|
mark(while (true) { try { while (true) { continue@outer } } finally { return "OK" } })
|
||||||
|
magic[VALUE_CONSUMER](true|<v0>) -> <v1>
|
||||||
|
L4 [body entry point]:
|
||||||
|
3 mark({ try { while (true) { continue@outer } } finally { return "OK" } })
|
||||||
|
mark(try { while (true) { continue@outer } } finally { return "OK" })
|
||||||
|
jmp?(L7) NEXT:[mark({ return "OK" }), mark({ while (true) { continue@outer } })]
|
||||||
|
4 mark({ while (true) { continue@outer } })
|
||||||
|
L8 [loop entry point]:
|
||||||
|
L12 [condition entry point]:
|
||||||
|
r(true) -> <v2>
|
||||||
|
mark(while (true) { continue@outer })
|
||||||
|
magic[VALUE_CONSUMER](true|<v2>) -> <v3>
|
||||||
|
L10 [body entry point]:
|
||||||
|
5 mark({ continue@outer })
|
||||||
|
L13 [start finally]:
|
||||||
|
6 mark({ return "OK" })
|
||||||
|
mark("OK")
|
||||||
|
r("OK") -> <v4>
|
||||||
|
ret(*|<v4>) L1 NEXT:[<END>]
|
||||||
|
L14 [finish finally]:
|
||||||
|
- 5 jmp(L6) NEXT:[r(true) -> <v0>] PREV:[]
|
||||||
|
- 4 jmp(L8) NEXT:[r(true) -> <v2>] PREV:[]
|
||||||
|
L9 [loop exit point]:
|
||||||
|
L11 [body exit point]:
|
||||||
|
- read (Unit) PREV:[]
|
||||||
|
- 3 jmp(L15) NEXT:[mark({ return "OK" })] PREV:[]
|
||||||
|
L7 [onExceptionToFinallyBlock]:
|
||||||
|
6 mark({ return "OK" }) PREV:[jmp?(L7)]
|
||||||
|
mark("OK")
|
||||||
|
r("OK") -> <v4>
|
||||||
|
ret(*|<v4>) L1 NEXT:[<END>]
|
||||||
|
- 3 jmp(error) NEXT:[<ERROR>] PREV:[]
|
||||||
|
L15 [skipFinallyToErrorBlock]:
|
||||||
|
- 6 mark({ return "OK" }) PREV:[]
|
||||||
|
- mark("OK") PREV:[]
|
||||||
|
- r("OK") -> <v4> PREV:[]
|
||||||
|
- ret(*|<v4>) L1 NEXT:[<END>] PREV:[]
|
||||||
|
- 3 merge(try { while (true) { continue@outer } } finally { return "OK" }|!<v7>) -> <v8> PREV:[]
|
||||||
|
- 2 jmp(L2) NEXT:[r(true) -> <v0>] PREV:[]
|
||||||
|
L3 [loop exit point]:
|
||||||
|
L5 [body exit point]:
|
||||||
|
- read (Unit) PREV:[]
|
||||||
|
L1:
|
||||||
|
1 <END> NEXT:[<SINK>] PREV:[ret(*|<v4>) L1, ret(*|<v4>) L1]
|
||||||
|
error:
|
||||||
|
<ERROR> PREV:[]
|
||||||
|
sink:
|
||||||
|
<SINK> PREV:[<ERROR>, <END>]
|
||||||
|
=====================
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
fun foo() {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
continue@outer
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("OK")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(): String {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
continue@outer
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
== foo ==
|
||||||
|
fun foo() {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
continue@outer
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println("OK")
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
<v1>: * NEW: magic[VALUE_CONSUMER](true|<v0>) -> <v1>
|
||||||
|
<v3>: * NEW: magic[VALUE_CONSUMER](true|<v2>) -> <v3>
|
||||||
|
true <v0>: Boolean NEW: r(true) -> <v0>
|
||||||
|
true <v2>: Boolean NEW: r(true) -> <v2>
|
||||||
|
continue@outer !<v5>: *
|
||||||
|
{ continue@outer } !<v5>: * COPY
|
||||||
|
while (true) { continue@outer } !<v6>: *
|
||||||
|
{ while (true) { continue@outer } } !<v6>: * COPY
|
||||||
|
break !<v4>: *
|
||||||
|
{ break } !<v4>: * COPY
|
||||||
|
try { while (true) { continue@outer } } finally { break } <v7>: * NEW: merge(try { while (true) { continue@outer } } finally { break }|!<v6>) -> <v7>
|
||||||
|
{ try { while (true) { continue@outer } } finally { break } } <v7>: * COPY
|
||||||
|
while (true) { try { while (true) { continue@outer } } finally { break } } !<v8>: *
|
||||||
|
outer@while (true) { try { while (true) { continue@outer } } finally { break } } !<v8>: * COPY
|
||||||
|
println !<v10>: *
|
||||||
|
"OK" <v9>: * NEW: r("OK") -> <v9>
|
||||||
|
println("OK") <v11>: * NEW: magic[UNRESOLVED_CALL](println("OK")|<v9>, !<v10>) -> <v11>
|
||||||
|
{ outer@while (true) { try { while (true) { continue@outer } } finally { break } } println("OK") } <v11>: * COPY
|
||||||
|
=====================
|
||||||
|
== bar ==
|
||||||
|
fun bar(): String {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
continue@outer
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
<v1>: * NEW: magic[VALUE_CONSUMER](true|<v0>) -> <v1>
|
||||||
|
<v3>: * NEW: magic[VALUE_CONSUMER](true|<v2>) -> <v3>
|
||||||
|
true <v0>: Boolean NEW: r(true) -> <v0>
|
||||||
|
true <v2>: Boolean NEW: r(true) -> <v2>
|
||||||
|
continue@outer !<v6>: *
|
||||||
|
{ continue@outer } !<v6>: * COPY
|
||||||
|
while (true) { continue@outer } !<v7>: *
|
||||||
|
{ while (true) { continue@outer } } !<v7>: * COPY
|
||||||
|
"OK" <v4>: String NEW: r("OK") -> <v4>
|
||||||
|
return "OK" !<v5>: *
|
||||||
|
{ return "OK" } !<v5>: * COPY
|
||||||
|
try { while (true) { continue@outer } } finally { return "OK" } <v8>: * NEW: merge(try { while (true) { continue@outer } } finally { return "OK" }|!<v7>) -> <v8>
|
||||||
|
{ try { while (true) { continue@outer } } finally { return "OK" } } <v8>: * COPY
|
||||||
|
while (true) { try { while (true) { continue@outer } } finally { return "OK" } } !<v9>: *
|
||||||
|
outer@while (true) { try { while (true) { continue@outer } } finally { return "OK" } } !<v9>: * COPY
|
||||||
|
{ outer@while (true) { try { while (true) { continue@outer } } finally { return "OK" } } } !<v9>: * COPY
|
||||||
|
=====================
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
== test ==
|
||||||
|
fun test() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass(val x: Int) {
|
||||||
|
init {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
constructor() : this(42) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fun foo() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
L0:
|
||||||
|
1 <START>
|
||||||
|
2 mark({ while (true) { class LocalClass(val x: Int) { init { break } constructor() : this(42) { break } fun foo() { break } } } })
|
||||||
|
L2 [loop entry point]:
|
||||||
|
L6 [condition entry point]:
|
||||||
|
r(true) -> <v0> PREV:[mark({ while (true) { class LocalClass(val x: Int) { init { break } constructor() : this(42) { break } fun foo() { break } } } }), jmp(L2)]
|
||||||
|
mark(while (true) { class LocalClass(val x: Int) { init { break } constructor() : this(42) { break } fun foo() { break } } })
|
||||||
|
magic[VALUE_CONSUMER](true|<v0>) -> <v1>
|
||||||
|
L4 [body entry point]:
|
||||||
|
3 mark({ class LocalClass(val x: Int) { init { break } constructor() : this(42) { break } fun foo() { break } } })
|
||||||
|
jmp?(L7) NEXT:[jmp(L2), v(val x: Int)]
|
||||||
|
v(val x: Int)
|
||||||
|
magic[FAKE_INITIALIZER](val x: Int) -> <v2>
|
||||||
|
w(x|<v2>)
|
||||||
|
4 mark({ break })
|
||||||
|
3 jmp?(L8) NEXT:[jmp(L2), d(fun foo() { break })]
|
||||||
|
d(fun foo() { break }) NEXT:[<SINK>]
|
||||||
|
L7 [after local class]:
|
||||||
|
L8 [after local declaration]:
|
||||||
|
2 jmp(L2) NEXT:[r(true) -> <v0>] PREV:[jmp?(L7), jmp?(L8)]
|
||||||
|
L3 [loop exit point]:
|
||||||
|
L5 [body exit point]:
|
||||||
|
- read (Unit) PREV:[]
|
||||||
|
L1:
|
||||||
|
1 <END> NEXT:[<SINK>] PREV:[]
|
||||||
|
error:
|
||||||
|
<ERROR> PREV:[]
|
||||||
|
sink:
|
||||||
|
<SINK> PREV:[<ERROR>, <END>, d(fun foo() { break })]
|
||||||
|
=====================
|
||||||
|
== foo ==
|
||||||
|
fun foo() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
L9:
|
||||||
|
4 <START>
|
||||||
|
5 mark({ break })
|
||||||
|
L10:
|
||||||
|
4 <END> NEXT:[<SINK>]
|
||||||
|
error:
|
||||||
|
<ERROR> PREV:[]
|
||||||
|
sink:
|
||||||
|
<SINK> PREV:[<ERROR>, <END>]
|
||||||
|
=====================
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
fun test() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass(val x: Int) {
|
||||||
|
init {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
constructor() : this(42) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fun foo() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
== test ==
|
||||||
|
fun test() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass(val x: Int) {
|
||||||
|
init {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
constructor() : this(42) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fun foo() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
<v1>: * NEW: magic[VALUE_CONSUMER](true|<v0>) -> <v1>
|
||||||
|
<v2>: Int NEW: magic[FAKE_INITIALIZER](val x: Int) -> <v2>
|
||||||
|
true <v0>: Boolean NEW: r(true) -> <v0>
|
||||||
|
break !<v3>: *
|
||||||
|
{ break } !<v3>: * COPY
|
||||||
|
while (true) { class LocalClass(val x: Int) { init { break } constructor() : this(42) { break } fun foo() { break } } } !<v4>: *
|
||||||
|
{ while (true) { class LocalClass(val x: Int) { init { break } constructor() : this(42) { break } fun foo() { break } } } } !<v4>: * COPY
|
||||||
|
=====================
|
||||||
|
== foo ==
|
||||||
|
fun foo() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
break !<v0>: *
|
||||||
|
{ break } !<v0>: * COPY
|
||||||
|
=====================
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fun box(): String {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
fun foo() {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
<!UNREACHABLE_CODE!>continue@outer<!>
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"OK".hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(): String {
|
||||||
|
outer@while (true) {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
<!UNREACHABLE_CODE!>continue@outer<!>
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun bar(): kotlin.String
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
fun test() {
|
||||||
|
while (true) {
|
||||||
|
fun local1() {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
while (true) {
|
||||||
|
<!UNUSED_LAMBDA_EXPRESSION!>{
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>continue<!>
|
||||||
|
}<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test3() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass {
|
||||||
|
init {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>continue<!>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test4() {
|
||||||
|
while (true) {
|
||||||
|
object: Any() {
|
||||||
|
init {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test5() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass(val x: Int) {
|
||||||
|
constructor() : this(42) {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!>
|
||||||
|
}
|
||||||
|
constructor(y: Double) : this(y.toInt()) {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>continue<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test6() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass(val x: Int) {
|
||||||
|
init {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!>
|
||||||
|
}
|
||||||
|
init {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>continue<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test7() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass {
|
||||||
|
val x: Int = if (true) {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!>
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>continue<!>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test8() {
|
||||||
|
while (true) {
|
||||||
|
class LocalClass(val x: Int) {
|
||||||
|
constructor() : this(if (true) { 42 } else { <!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!> })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test(): kotlin.Unit
|
||||||
|
public fun test2(): kotlin.Unit
|
||||||
|
public fun test3(): kotlin.Unit
|
||||||
|
public fun test4(): kotlin.Unit
|
||||||
|
public fun test5(): kotlin.Unit
|
||||||
|
public fun test6(): kotlin.Unit
|
||||||
|
public fun test7(): kotlin.Unit
|
||||||
|
public fun test8(): kotlin.Unit
|
||||||
@@ -166,6 +166,18 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cfg/controlStructures"), Pattern.compile("^(.+)\\.kt$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cfg/controlStructures"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("breakContinueInTryFinally.kt")
|
||||||
|
public void testBreakContinueInTryFinally() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/breakContinueInTryFinally.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("breakInsideLocal.kt")
|
||||||
|
public void testBreakInsideLocal() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/breakInsideLocal.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("continueInDoWhile.kt")
|
@TestMetadata("continueInDoWhile.kt")
|
||||||
public void testContinueInDoWhile() throws Exception {
|
public void testContinueInDoWhile() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/continueInDoWhile.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/continueInDoWhile.kt");
|
||||||
|
|||||||
@@ -168,6 +168,18 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cfg/controlStructures"), Pattern.compile("^(.+)\\.kt$"), true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cfg/controlStructures"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("breakContinueInTryFinally.kt")
|
||||||
|
public void testBreakContinueInTryFinally() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/breakContinueInTryFinally.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("breakInsideLocal.kt")
|
||||||
|
public void testBreakInsideLocal() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/breakInsideLocal.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("continueInDoWhile.kt")
|
@TestMetadata("continueInDoWhile.kt")
|
||||||
public void testContinueInDoWhile() throws Exception {
|
public void testContinueInDoWhile() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/continueInDoWhile.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cfg/controlStructures/continueInDoWhile.kt");
|
||||||
|
|||||||
@@ -2847,6 +2847,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("breakContinueInTryFinally.kt")
|
||||||
|
public void testBreakContinueInTryFinally() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/breakContinueInTryFinally.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("breakInsideLocal.kt")
|
||||||
|
public void testBreakInsideLocal() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/breakInsideLocal.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("breakOrContinueInLoopCondition.kt")
|
@TestMetadata("breakOrContinueInLoopCondition.kt")
|
||||||
public void testBreakOrContinueInLoopCondition() throws Exception {
|
public void testBreakOrContinueInLoopCondition() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/breakOrContinueInLoopCondition.kt");
|
||||||
|
|||||||
@@ -3421,6 +3421,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("breakInFinally.kt")
|
||||||
|
public void testBreakInFinally() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/breakInFinally.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compareBoxedIntegerToZero.kt")
|
@TestMetadata("compareBoxedIntegerToZero.kt")
|
||||||
public void testCompareBoxedIntegerToZero() throws Exception {
|
public void testCompareBoxedIntegerToZero() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/compareBoxedIntegerToZero.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/compareBoxedIntegerToZero.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user