From e0f37bbef05c65302f068fdeae81b0c4e18ed98d Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 15 May 2014 15:24:14 +0400 Subject: [PATCH] Generate parse error on label without name '@' --- .../jet/lang/cfg/JetControlFlowProcessor.java | 3 +- .../lang/parsing/JetExpressionParsing.java | 7 + .../BasicExpressionTypingVisitor.java | 2 +- .../lang/types/expressions/LabelResolver.java | 7 +- .../controlStructures/Finally.instructions | 528 +++++++++--------- .../testData/cfg/controlStructures/Finally.kt | 32 +- .../diagnostics/tests/BreakContinue.kt | 8 +- .../diagnostics/tests/FunctionReturnTypes.kt | 2 +- .../diagnostics/tests/LValueAssignment.kt | 4 +- .../return/LocalReturnExplicitLabelParens.kt | 2 +- .../tests/labels/labelsMustBeNamed.kt | 36 ++ .../TypeMismatchOnUnaryOperations.kt | 7 +- .../diagnostics/tests/regressions/kt411.kt | 24 +- .../checkers/JetDiagnosticsTestGenerated.java | 5 + .../jetbrains/jet/lang/resolve/name/Name.java | 7 - 15 files changed, 358 insertions(+), 316 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 93faf1b5c81..6f09b27d9d5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -697,8 +697,7 @@ public class JetControlFlowProcessor { JetSimpleNameExpression labelElement = expression.getTargetLabel(); JetElement subroutine; String labelName = expression.getLabelName(); - if (labelElement != null) { - assert labelName != null; + if (labelElement != null && labelName != null) { PsiElement labeledElement = trace.get(BindingContext.LABEL_TARGET, labelElement); if (labeledElement != null) { assert labeledElement instanceof JetElement; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index c1be5288cf1..659ff607f22 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -1605,6 +1605,13 @@ public class JetExpressionParsing extends AbstractJetParsing { */ private void parseLabel() { assert _at(LABEL_IDENTIFIER); + + String labelText = myBuilder.getTokenText(); + if ("@".equals(labelText)) { + errorAndAdvance("Label must be named"); + return; + } + PsiBuilder.Marker labelWrap = mark(); PsiBuilder.Marker mark = mark(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index aa1629f2108..06b1d782b9d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -377,7 +377,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { String labelName = expression.getLabelName(); if (labelName != null) { LabelResolver.LabeledReceiverResolutionResult resolutionResult = - LabelResolver.INSTANCE.resolveThisOrSuperLabel(expression, context, Name.identifierForLabel(labelName)); + LabelResolver.INSTANCE.resolveThisOrSuperLabel(expression, context, Name.identifier(labelName)); if (onlyClassReceivers && resolutionResult.success()) { if (!isDeclaredInClass(resolutionResult.getReceiverParameterDescriptor())) { return LabelResolver.LabeledReceiverResolutionResult.labelResolutionSuccess(NO_RECEIVER_PARAMETER); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java index d14352400d7..466ab14c43c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/LabelResolver.java @@ -60,7 +60,10 @@ public class LabelResolver { @Nullable private Name getLabelNameIfAny(@NotNull PsiElement element) { if (element instanceof JetLabeledExpression) { - return Name.identifierForLabel(((JetLabeledExpression) element).getLabelName()); + String labelName = ((JetLabeledExpression) element).getLabelName(); + if (labelName != null) { + return Name.identifier(labelName); + } } if (element instanceof JetFunctionLiteralExpression) { return getCallerName((JetFunctionLiteralExpression) element); @@ -121,7 +124,7 @@ public class LabelResolver { String name = expression.getLabelName(); if (labelElement == null || name == null) return null; - Name labelName = Name.identifierForLabel(name); + Name labelName = Name.identifier(name); Collection declarationsByLabel = context.scope.getDeclarationsByLabel(labelName); int size = declarationsByLabel.size(); diff --git a/compiler/testData/cfg/controlStructures/Finally.instructions b/compiler/testData/cfg/controlStructures/Finally.instructions index 8521596ca16..10858782464 100644 --- a/compiler/testData/cfg/controlStructures/Finally.instructions +++ b/compiler/testData/cfg/controlStructures/Finally.instructions @@ -85,9 +85,9 @@ sink: fun t3() { try { 1 - @{ () -> + @l{ () -> if (2 > 3) { - return@ + return@l } } } finally { @@ -97,70 +97,70 @@ fun t3() { --------------------- L0: 1 - 2 mark({ try { 1 @{ () -> if (2 > 3) { return@ } } } finally { 2 } }) - mark(try { 1 @{ () -> if (2 > 3) { return@ } } } finally { 2 }) - jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 @{ () -> if (2 > 3) { return@ } } })] - 3 mark({ 1 @{ () -> if (2 > 3) { return@ } } }) + 2 mark({ try { 1 @l{ () -> if (2 > 3) { return@l } } } finally { 2 } }) + mark(try { 1 @l{ () -> if (2 > 3) { return@l } } } finally { 2 }) + jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 @l{ () -> if (2 > 3) { return@l } } })] + 3 mark({ 1 @l{ () -> if (2 > 3) { return@l } } }) r(1) - mark(@{ () -> if (2 > 3) { return@ } }) - mark({ () -> if (2 > 3) { return@ } }) - jmp?(L3) NEXT:[r({ () -> if (2 > 3) { return@ } }), d({ () -> if (2 > 3) { return@ } })] - d({ () -> if (2 > 3) { return@ } }) NEXT:[] + mark(@l{ () -> if (2 > 3) { return@l } }) + mark({ () -> if (2 > 3) { return@l } }) + jmp?(L3) NEXT:[r({ () -> if (2 > 3) { return@l } }), d({ () -> if (2 > 3) { return@l } })] + d({ () -> if (2 > 3) { return@l } }) NEXT:[] L3: - r({ () -> if (2 > 3) { return@ } }) PREV:[jmp?(L3)] - 2 jmp(L8 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] + r({ () -> if (2 > 3) { return@l } }) PREV:[jmp?(L3)] + 2 jmp(L8 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] L2 [onExceptionToFinallyBlock]: L9 [start finally]: - 3 mark({ 2 }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])] + 3 mark({ 2 }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])] r(2) L10 [finish finally]: - 2 jmp(error) NEXT:[] + 2 jmp(error) NEXT:[] L8 [skipFinallyToErrorBlock]: - 3 mark({ 2 }) PREV:[jmp(L8 [skipFinallyToErrorBlock])] + 3 mark({ 2 }) PREV:[jmp(L8 [skipFinallyToErrorBlock])] r(2) L1: - 1 NEXT:[] + 1 NEXT:[] error: - PREV:[jmp(error)] + PREV:[jmp(error)] sink: - PREV:[, , d({ () -> if (2 > 3) { return@ } })] + PREV:[, , d({ () -> if (2 > 3) { return@l } })] ===================== == anonymous_0 == { () -> if (2 > 3) { - return@ + return@l } } --------------------- L4: 4 - 5 mark(if (2 > 3) { return@ }) - mark(if (2 > 3) { return@ }) + 5 mark(if (2 > 3) { return@l }) + mark(if (2 > 3) { return@l }) mark(2 > 3) r(2) r(3) call(>, compareTo) - jf(L6) NEXT:[read (Unit), mark({ return@ })] - 6 mark({ return@ }) - ret L5 NEXT:[] -- 5 jmp(L7) NEXT:[] PREV:[] + jf(L6) NEXT:[read (Unit), mark({ return@l })] + 6 mark({ return@l }) + ret L5 NEXT:[] +- 5 jmp(L7) NEXT:[] PREV:[] L6: - read (Unit) PREV:[jf(L6)] + read (Unit) PREV:[jf(L6)] L5: L7: - 4 NEXT:[] PREV:[ret L5, read (Unit)] + 4 NEXT:[] PREV:[ret L5, read (Unit)] error: - PREV:[] + PREV:[] sink: - PREV:[, ] + PREV:[, ] ===================== == t4 == fun t4() { - @{ () -> + @l{ () -> try { 1 if (2 > 3) { - return@ + return@l } } finally { 2 @@ -170,26 +170,26 @@ fun t4() { --------------------- L0: 1 - 2 mark({ @{ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } } }) - mark(@{ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } }) - mark({ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } }) - jmp?(L2) NEXT:[r({ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } }), d({ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } })] - d({ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } }) NEXT:[] + 2 mark({ @l{ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } } }) + mark(@l{ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } }) + mark({ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } }) + jmp?(L2) NEXT:[r({ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } }), d({ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } })] + d({ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } }) NEXT:[] L2: - r({ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } }) PREV:[jmp?(L2)] + r({ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } }) PREV:[jmp?(L2)] L1: - 1 NEXT:[] + 1 NEXT:[] error: - PREV:[] + PREV:[] sink: - PREV:[, , d({ () -> try { 1 if (2 > 3) { return@ } } finally { 2 } })] + PREV:[, , d({ () -> try { 1 if (2 > 3) { return@l } } finally { 2 } })] ===================== == anonymous_1 == { () -> try { 1 if (2 > 3) { - return@ + return@l } } finally { 2 @@ -198,49 +198,49 @@ sink: --------------------- L3: 3 - 4 mark(try { 1 if (2 > 3) { return@ } } finally { 2 }) - mark(try { 1 if (2 > 3) { return@ } } finally { 2 }) - jmp?(L5 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 if (2 > 3) { return@ } })] - 5 mark({ 1 if (2 > 3) { return@ } }) + 4 mark(try { 1 if (2 > 3) { return@l } } finally { 2 }) + mark(try { 1 if (2 > 3) { return@l } } finally { 2 }) + jmp?(L5 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 if (2 > 3) { return@l } })] + 5 mark({ 1 if (2 > 3) { return@l } }) r(1) - mark(if (2 > 3) { return@ }) + mark(if (2 > 3) { return@l }) mark(2 > 3) r(2) r(3) call(>, compareTo) - jf(L6) NEXT:[read (Unit), mark({ return@ })] - 6 mark({ return@ }) + jf(L6) NEXT:[read (Unit), mark({ return@l })] + 6 mark({ return@l }) L7 [start finally]: 7 mark({ 2 }) r(2) L8 [finish finally]: - 6 ret L4 NEXT:[] -- 5 jmp(L9) NEXT:[jmp(L10 [skipFinallyToErrorBlock])] PREV:[] + 6 ret L4 NEXT:[] +- 5 jmp(L9) NEXT:[jmp(L10 [skipFinallyToErrorBlock])] PREV:[] L6: - read (Unit) PREV:[jf(L6)] + read (Unit) PREV:[jf(L6)] L9: - 4 jmp(L10 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] + 4 jmp(L10 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] L5 [onExceptionToFinallyBlock]: - 7 mark({ 2 }) PREV:[jmp?(L5 [onExceptionToFinallyBlock])] + 7 mark({ 2 }) PREV:[jmp?(L5 [onExceptionToFinallyBlock])] r(2) - 4 jmp(error) NEXT:[] + 4 jmp(error) NEXT:[] L10 [skipFinallyToErrorBlock]: - 7 mark({ 2 }) PREV:[jmp(L10 [skipFinallyToErrorBlock])] + 7 mark({ 2 }) PREV:[jmp(L10 [skipFinallyToErrorBlock])] r(2) L4: - 3 NEXT:[] PREV:[ret L4, r(2)] + 3 NEXT:[] PREV:[ret L4, r(2)] error: - PREV:[jmp(error)] + PREV:[jmp(error)] sink: - PREV:[, ] + PREV:[, ] ===================== == t5 == fun t5() { - @ while(true) { + @l while(true) { try { 1 if (2 > 3) { - break @ + break @l } } finally { 2 @@ -250,59 +250,59 @@ fun t5() { --------------------- L0: 1 - 2 mark({ @ while(true) { try { 1 if (2 > 3) { break @ } } finally { 2 } } }) - mark(@ while(true) { try { 1 if (2 > 3) { break @ } } finally { 2 } }) - mark(while(true) { try { 1 if (2 > 3) { break @ } } finally { 2 } }) + 2 mark({ @l while(true) { try { 1 if (2 > 3) { break @l } } finally { 2 } } }) + mark(@l while(true) { try { 1 if (2 > 3) { break @l } } finally { 2 } }) + mark(while(true) { try { 1 if (2 > 3) { break @l } } finally { 2 } }) L2 [loop entry point]: L5 [condition entry point]: - r(true) PREV:[mark(while(true) { try { 1 if (2 > 3) { break @ } } finally { 2 } }), jmp(L2 [loop entry point])] + r(true) PREV:[mark(while(true) { try { 1 if (2 > 3) { break @l } } finally { 2 } }), jmp(L2 [loop entry point])] L4 [body entry point]: - 3 mark({ try { 1 if (2 > 3) { break @ } } finally { 2 } }) - mark(try { 1 if (2 > 3) { break @ } } finally { 2 }) - jmp?(L6 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 if (2 > 3) { break @ } })] - 4 mark({ 1 if (2 > 3) { break @ } }) + 3 mark({ try { 1 if (2 > 3) { break @l } } finally { 2 } }) + mark(try { 1 if (2 > 3) { break @l } } finally { 2 }) + jmp?(L6 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 if (2 > 3) { break @l } })] + 4 mark({ 1 if (2 > 3) { break @l } }) r(1) - mark(if (2 > 3) { break @ }) + mark(if (2 > 3) { break @l }) mark(2 > 3) r(2) r(3) call(>, compareTo) - jf(L7) NEXT:[read (Unit), mark({ break @ })] - 5 mark({ break @ }) + jf(L7) NEXT:[read (Unit), mark({ break @l })] + 5 mark({ break @l }) L8 [start finally]: 6 mark({ 2 }) r(2) L9 [finish finally]: - 5 jmp(L3 [loop exit point]) NEXT:[read (Unit)] -- 4 jmp(L10) NEXT:[jmp(L11 [skipFinallyToErrorBlock])] PREV:[] + 5 jmp(L3 [loop exit point]) NEXT:[read (Unit)] +- 4 jmp(L10) NEXT:[jmp(L11 [skipFinallyToErrorBlock])] PREV:[] L7: - read (Unit) PREV:[jf(L7)] + read (Unit) PREV:[jf(L7)] L10: - 3 jmp(L11 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] + 3 jmp(L11 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] L6 [onExceptionToFinallyBlock]: - 6 mark({ 2 }) PREV:[jmp?(L6 [onExceptionToFinallyBlock])] + 6 mark({ 2 }) PREV:[jmp?(L6 [onExceptionToFinallyBlock])] r(2) - 3 jmp(error) NEXT:[] + 3 jmp(error) NEXT:[] L11 [skipFinallyToErrorBlock]: - 6 mark({ 2 }) PREV:[jmp(L11 [skipFinallyToErrorBlock])] + 6 mark({ 2 }) PREV:[jmp(L11 [skipFinallyToErrorBlock])] r(2) - 2 jmp(L2 [loop entry point]) NEXT:[r(true)] + 2 jmp(L2 [loop entry point]) NEXT:[r(true)] L3 [loop exit point]: - read (Unit) PREV:[jmp(L3 [loop exit point])] + read (Unit) PREV:[jmp(L3 [loop exit point])] L1: - 1 NEXT:[] + 1 NEXT:[] error: - PREV:[jmp(error)] + PREV:[jmp(error)] sink: - PREV:[, ] + PREV:[, ] ===================== == t6 == fun t6() { try { - @ while(true) { + @l while(true) { 1 if (2 > 3) { - break @ + break @l } } 5 @@ -313,25 +313,86 @@ fun t6() { --------------------- L0: 1 - 2 mark({ try { @ while(true) { 1 if (2 > 3) { break @ } } 5 } finally { 2 } }) - mark(try { @ while(true) { 1 if (2 > 3) { break @ } } 5 } finally { 2 }) - jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @ while(true) { 1 if (2 > 3) { break @ } } 5 })] - 3 mark({ @ while(true) { 1 if (2 > 3) { break @ } } 5 }) - mark(@ while(true) { 1 if (2 > 3) { break @ } }) - mark(while(true) { 1 if (2 > 3) { break @ } }) + 2 mark({ try { @l while(true) { 1 if (2 > 3) { break @l } } 5 } finally { 2 } }) + mark(try { @l while(true) { 1 if (2 > 3) { break @l } } 5 } finally { 2 }) + jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @l while(true) { 1 if (2 > 3) { break @l } } 5 })] + 3 mark({ @l while(true) { 1 if (2 > 3) { break @l } } 5 }) + mark(@l while(true) { 1 if (2 > 3) { break @l } }) + mark(while(true) { 1 if (2 > 3) { break @l } }) L3 [loop entry point]: L6 [condition entry point]: - r(true) PREV:[mark(while(true) { 1 if (2 > 3) { break @ } }), jmp(L3 [loop entry point])] + r(true) PREV:[mark(while(true) { 1 if (2 > 3) { break @l } }), jmp(L3 [loop entry point])] L5 [body entry point]: - 4 mark({ 1 if (2 > 3) { break @ } }) + 4 mark({ 1 if (2 > 3) { break @l } }) r(1) - mark(if (2 > 3) { break @ }) + mark(if (2 > 3) { break @l }) mark(2 > 3) r(2) r(3) call(>, compareTo) - jf(L7) NEXT:[read (Unit), mark({ break @ })] - 5 mark({ break @ }) + jf(L7) NEXT:[read (Unit), mark({ break @l })] + 5 mark({ break @l }) + jmp(L4 [loop exit point]) NEXT:[read (Unit)] +- 4 jmp(L8) NEXT:[jmp(L3 [loop entry point])] PREV:[] +L7: + read (Unit) PREV:[jf(L7)] +L8: + 3 jmp(L3 [loop entry point]) NEXT:[r(true)] +L4 [loop exit point]: + read (Unit) PREV:[jmp(L4 [loop exit point])] + r(5) + 2 jmp(L9 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] +L2 [onExceptionToFinallyBlock]: +L10 [start finally]: + 3 mark({ 2 }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])] + r(2) +L11 [finish finally]: + 2 jmp(error) NEXT:[] +L9 [skipFinallyToErrorBlock]: + 3 mark({ 2 }) PREV:[jmp(L9 [skipFinallyToErrorBlock])] + r(2) +L1: + 1 NEXT:[] +error: + PREV:[jmp(error)] +sink: + PREV:[, ] +===================== +== t7 == +fun t7() { + try { + @l while(true) { + 1 + if (2 > 3) { + break @l + } + } + } finally { + 2 + } +} +--------------------- +L0: + 1 + 2 mark({ try { @l while(true) { 1 if (2 > 3) { break @l } } } finally { 2 } }) + mark(try { @l while(true) { 1 if (2 > 3) { break @l } } } finally { 2 }) + jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @l while(true) { 1 if (2 > 3) { break @l } } })] + 3 mark({ @l while(true) { 1 if (2 > 3) { break @l } } }) + mark(@l while(true) { 1 if (2 > 3) { break @l } }) + mark(while(true) { 1 if (2 > 3) { break @l } }) +L3 [loop entry point]: +L6 [condition entry point]: + r(true) PREV:[mark(while(true) { 1 if (2 > 3) { break @l } }), jmp(L3 [loop entry point])] +L5 [body entry point]: + 4 mark({ 1 if (2 > 3) { break @l } }) + r(1) + mark(if (2 > 3) { break @l }) + mark(2 > 3) + r(2) + r(3) + call(>, compareTo) + jf(L7) NEXT:[read (Unit), mark({ break @l })] + 5 mark({ break @l }) jmp(L4 [loop exit point]) NEXT:[read (Unit)] - 4 jmp(L8) NEXT:[jmp(L3 [loop entry point])] PREV:[] L7: @@ -340,7 +401,6 @@ L8: 3 jmp(L3 [loop entry point]) NEXT:[r(true)] L4 [loop exit point]: read (Unit) PREV:[jmp(L4 [loop exit point])] - r(5) 2 jmp(L9 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] L2 [onExceptionToFinallyBlock]: L10 [start finally]: @@ -358,73 +418,13 @@ error: sink: PREV:[, ] ===================== -== t7 == -fun t7() { - try { - @ while(true) { - 1 - if (2 > 3) { - break @ - } - } - } finally { - 2 - } -} ---------------------- -L0: - 1 - 2 mark({ try { @ while(true) { 1 if (2 > 3) { break @ } } } finally { 2 } }) - mark(try { @ while(true) { 1 if (2 > 3) { break @ } } } finally { 2 }) - jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @ while(true) { 1 if (2 > 3) { break @ } } })] - 3 mark({ @ while(true) { 1 if (2 > 3) { break @ } } }) - mark(@ while(true) { 1 if (2 > 3) { break @ } }) - mark(while(true) { 1 if (2 > 3) { break @ } }) -L3 [loop entry point]: -L6 [condition entry point]: - r(true) PREV:[mark(while(true) { 1 if (2 > 3) { break @ } }), jmp(L3 [loop entry point])] -L5 [body entry point]: - 4 mark({ 1 if (2 > 3) { break @ } }) - r(1) - mark(if (2 > 3) { break @ }) - mark(2 > 3) - r(2) - r(3) - call(>, compareTo) - jf(L7) NEXT:[read (Unit), mark({ break @ })] - 5 mark({ break @ }) - jmp(L4 [loop exit point]) NEXT:[read (Unit)] -- 4 jmp(L8) NEXT:[jmp(L3 [loop entry point])] PREV:[] -L7: - read (Unit) PREV:[jf(L7)] -L8: - 3 jmp(L3 [loop entry point]) NEXT:[r(true)] -L4 [loop exit point]: - read (Unit) PREV:[jmp(L4 [loop exit point])] - 2 jmp(L9 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] -L2 [onExceptionToFinallyBlock]: -L10 [start finally]: - 3 mark({ 2 }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])] - r(2) -L11 [finish finally]: - 2 jmp(error) NEXT:[] -L9 [skipFinallyToErrorBlock]: - 3 mark({ 2 }) PREV:[jmp(L9 [skipFinallyToErrorBlock])] - r(2) -L1: - 1 NEXT:[] -error: - PREV:[jmp(error)] -sink: - PREV:[, ] -===================== == t8 == fun t8(a : Int) { - @ for (i in 1..a) { + @l for (i in 1..a) { try { 1 if (2 > 3) { - continue @ + continue @l } } finally { 2 @@ -436,65 +436,65 @@ L0: 1 v(a : Int) w(a) - 2 mark({ @ for (i in 1..a) { try { 1 if (2 > 3) { continue @ } } finally { 2 } } }) - mark(@ for (i in 1..a) { try { 1 if (2 > 3) { continue @ } } finally { 2 } }) - 3 mark(for (i in 1..a) { try { 1 if (2 > 3) { continue @ } } finally { 2 } }) + 2 mark({ @l for (i in 1..a) { try { 1 if (2 > 3) { continue @l } } finally { 2 } } }) + mark(@l for (i in 1..a) { try { 1 if (2 > 3) { continue @l } } finally { 2 } }) + 3 mark(for (i in 1..a) { try { 1 if (2 > 3) { continue @l } } finally { 2 } }) mark(1..a) r(1) r(a) call(.., rangeTo) v(i) L3: - jmp?(L2) NEXT:[read (Unit), w(i)] + jmp?(L2) NEXT:[read (Unit), w(i)] L4 [loop entry point]: L5 [body entry point]: - w(i) PREV:[jmp?(L2), jmp(L4 [loop entry point]), jmp?(L4 [loop entry point])] - 4 mark({ try { 1 if (2 > 3) { continue @ } } finally { 2 } }) - mark(try { 1 if (2 > 3) { continue @ } } finally { 2 }) - jmp?(L6 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 if (2 > 3) { continue @ } })] - 5 mark({ 1 if (2 > 3) { continue @ } }) + w(i) PREV:[jmp?(L2), jmp(L4 [loop entry point]), jmp?(L4 [loop entry point])] + 4 mark({ try { 1 if (2 > 3) { continue @l } } finally { 2 } }) + mark(try { 1 if (2 > 3) { continue @l } } finally { 2 }) + jmp?(L6 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ 1 if (2 > 3) { continue @l } })] + 5 mark({ 1 if (2 > 3) { continue @l } }) r(1) - mark(if (2 > 3) { continue @ }) + mark(if (2 > 3) { continue @l }) mark(2 > 3) r(2) r(3) call(>, compareTo) - jf(L7) NEXT:[read (Unit), mark({ continue @ })] - 6 mark({ continue @ }) + jf(L7) NEXT:[read (Unit), mark({ continue @l })] + 6 mark({ continue @l }) L8 [start finally]: 7 mark({ 2 }) r(2) L9 [finish finally]: - 6 jmp(L4 [loop entry point]) NEXT:[w(i)] -- 5 jmp(L10) NEXT:[jmp(L11 [skipFinallyToErrorBlock])] PREV:[] + 6 jmp(L4 [loop entry point]) NEXT:[w(i)] +- 5 jmp(L10) NEXT:[jmp(L11 [skipFinallyToErrorBlock])] PREV:[] L7: - read (Unit) PREV:[jf(L7)] + read (Unit) PREV:[jf(L7)] L10: - 4 jmp(L11 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] + 4 jmp(L11 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] L6 [onExceptionToFinallyBlock]: - 7 mark({ 2 }) PREV:[jmp?(L6 [onExceptionToFinallyBlock])] + 7 mark({ 2 }) PREV:[jmp?(L6 [onExceptionToFinallyBlock])] r(2) - 4 jmp(error) NEXT:[] + 4 jmp(error) NEXT:[] L11 [skipFinallyToErrorBlock]: - 7 mark({ 2 }) PREV:[jmp(L11 [skipFinallyToErrorBlock])] + 7 mark({ 2 }) PREV:[jmp(L11 [skipFinallyToErrorBlock])] r(2) - 3 jmp?(L4 [loop entry point]) NEXT:[w(i), read (Unit)] + 3 jmp?(L4 [loop entry point]) NEXT:[w(i), read (Unit)] L2: - read (Unit) PREV:[jmp?(L2), jmp?(L4 [loop entry point])] + read (Unit) PREV:[jmp?(L2), jmp?(L4 [loop entry point])] L1: - 1 NEXT:[] + 1 NEXT:[] error: - PREV:[jmp(error)] + PREV:[jmp(error)] sink: - PREV:[, ] + PREV:[, ] ===================== == t9 == fun t9(a : Int) { try { - @ for (i in 1..a) { + @l for (i in 1..a) { 1 if (2 > 3) { - continue @ + continue @l } } 5 @@ -507,12 +507,81 @@ L0: 1 v(a : Int) w(a) - 2 mark({ try { @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } 5 } finally { 2 } }) - mark(try { @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } 5 } finally { 2 }) - jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } 5 })] - 3 mark({ @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } 5 }) - mark(@ for (i in 1..a) { 1 if (2 > 3) { continue @ } }) - 4 mark(for (i in 1..a) { 1 if (2 > 3) { continue @ } }) + 2 mark({ try { @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } 5 } finally { 2 } }) + mark(try { @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } 5 } finally { 2 }) + jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } 5 })] + 3 mark({ @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } 5 }) + mark(@l for (i in 1..a) { 1 if (2 > 3) { continue @l } }) + 4 mark(for (i in 1..a) { 1 if (2 > 3) { continue @l } }) + mark(1..a) + r(1) + r(a) + call(.., rangeTo) + v(i) +L4: + jmp?(L3) NEXT:[read (Unit), w(i)] +L5 [loop entry point]: +L6 [body entry point]: + w(i) PREV:[jmp?(L3), jmp(L5 [loop entry point]), jmp?(L5 [loop entry point])] + 5 mark({ 1 if (2 > 3) { continue @l } }) + r(1) + mark(if (2 > 3) { continue @l }) + mark(2 > 3) + r(2) + r(3) + call(>, compareTo) + jf(L7) NEXT:[read (Unit), mark({ continue @l })] + 6 mark({ continue @l }) + jmp(L5 [loop entry point]) NEXT:[w(i)] +- 5 jmp(L8) NEXT:[jmp?(L5 [loop entry point])] PREV:[] +L7: + read (Unit) PREV:[jf(L7)] +L8: + 4 jmp?(L5 [loop entry point]) NEXT:[w(i), read (Unit)] +L3: + read (Unit) PREV:[jmp?(L3), jmp?(L5 [loop entry point])] + 3 r(5) + 2 jmp(L9 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] +L2 [onExceptionToFinallyBlock]: +L10 [start finally]: + 3 mark({ 2 }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])] + r(2) +L11 [finish finally]: + 2 jmp(error) NEXT:[] +L9 [skipFinallyToErrorBlock]: + 3 mark({ 2 }) PREV:[jmp(L9 [skipFinallyToErrorBlock])] + r(2) +L1: + 1 NEXT:[] +error: + PREV:[jmp(error)] +sink: + PREV:[, ] +===================== +== t10 == +fun t10(a : Int) { + try { + @l for (i in 1..a) { + 1 + if (2 > 3) { + continue @l + } + } + } finally { + 2 + } +} +--------------------- +L0: + 1 + v(a : Int) + w(a) + 2 mark({ try { @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } } finally { 2 } }) + mark(try { @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } } finally { 2 }) + jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } })] + 3 mark({ @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } }) + mark(@l for (i in 1..a) { 1 if (2 > 3) { continue @l } }) + 4 mark(for (i in 1..a) { 1 if (2 > 3) { continue @l } }) mark(1..a) r(1) r(a) @@ -523,15 +592,15 @@ L4: L5 [loop entry point]: L6 [body entry point]: w(i) PREV:[jmp?(L3), jmp(L5 [loop entry point]), jmp?(L5 [loop entry point])] - 5 mark({ 1 if (2 > 3) { continue @ } }) + 5 mark({ 1 if (2 > 3) { continue @l } }) r(1) - mark(if (2 > 3) { continue @ }) + mark(if (2 > 3) { continue @l }) mark(2 > 3) r(2) r(3) call(>, compareTo) - jf(L7) NEXT:[read (Unit), mark({ continue @ })] - 6 mark({ continue @ }) + jf(L7) NEXT:[read (Unit), mark({ continue @l })] + 6 mark({ continue @l }) jmp(L5 [loop entry point]) NEXT:[w(i)] - 5 jmp(L8) NEXT:[jmp?(L5 [loop entry point])] PREV:[] L7: @@ -540,7 +609,6 @@ L8: 4 jmp?(L5 [loop entry point]) NEXT:[w(i), read (Unit)] L3: read (Unit) PREV:[jmp?(L3), jmp?(L5 [loop entry point])] - 3 r(5) 2 jmp(L9 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] L2 [onExceptionToFinallyBlock]: L10 [start finally]: @@ -558,74 +626,6 @@ error: sink: PREV:[, ] ===================== -== t10 == -fun t10(a : Int) { - try { - @ for (i in 1..a) { - 1 - if (2 > 3) { - continue @ - } - } - } finally { - 2 - } -} ---------------------- -L0: - 1 - v(a : Int) - w(a) - 2 mark({ try { @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } } finally { 2 } }) - mark(try { @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } } finally { 2 }) - jmp?(L2 [onExceptionToFinallyBlock]) NEXT:[mark({ 2 }), mark({ @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } })] - 3 mark({ @ for (i in 1..a) { 1 if (2 > 3) { continue @ } } }) - mark(@ for (i in 1..a) { 1 if (2 > 3) { continue @ } }) - 4 mark(for (i in 1..a) { 1 if (2 > 3) { continue @ } }) - mark(1..a) - r(1) - r(a) - call(.., rangeTo) - v(i) -L4: - jmp?(L3) NEXT:[read (Unit), w(i)] -L5 [loop entry point]: -L6 [body entry point]: - w(i) PREV:[jmp?(L3), jmp(L5 [loop entry point]), jmp?(L5 [loop entry point])] - 5 mark({ 1 if (2 > 3) { continue @ } }) - r(1) - mark(if (2 > 3) { continue @ }) - mark(2 > 3) - r(2) - r(3) - call(>, compareTo) - jf(L7) NEXT:[read (Unit), mark({ continue @ })] - 6 mark({ continue @ }) - jmp(L5 [loop entry point]) NEXT:[w(i)] -- 5 jmp(L8) NEXT:[jmp?(L5 [loop entry point])] PREV:[] -L7: - read (Unit) PREV:[jf(L7)] -L8: - 4 jmp?(L5 [loop entry point]) NEXT:[w(i), read (Unit)] -L3: - read (Unit) PREV:[jmp?(L3), jmp?(L5 [loop entry point])] - 2 jmp(L9 [skipFinallyToErrorBlock]) NEXT:[mark({ 2 })] -L2 [onExceptionToFinallyBlock]: -L10 [start finally]: - 3 mark({ 2 }) PREV:[jmp?(L2 [onExceptionToFinallyBlock])] - r(2) -L11 [finish finally]: - 2 jmp(error) NEXT:[] -L9 [skipFinallyToErrorBlock]: - 3 mark({ 2 }) PREV:[jmp(L9 [skipFinallyToErrorBlock])] - r(2) -L1: - 1 NEXT:[] -error: - PREV:[jmp(error)] -sink: - PREV:[, ] -===================== == t11 == fun t11() { try { diff --git a/compiler/testData/cfg/controlStructures/Finally.kt b/compiler/testData/cfg/controlStructures/Finally.kt index 9e41b453caf..f9e9f42cf6b 100644 --- a/compiler/testData/cfg/controlStructures/Finally.kt +++ b/compiler/testData/cfg/controlStructures/Finally.kt @@ -20,9 +20,9 @@ fun t2() { fun t3() { try { 1 - @{ () -> + @l{ () -> if (2 > 3) { - return@ + return@l } } } finally { @@ -31,11 +31,11 @@ fun t3() { } fun t4() { - @{ () -> + @l{ () -> try { 1 if (2 > 3) { - return@ + return@l } } finally { 2 @@ -44,11 +44,11 @@ fun t4() { } fun t5() { - @ while(true) { + @l while(true) { try { 1 if (2 > 3) { - break @ + break @l } } finally { 2 @@ -58,10 +58,10 @@ fun t5() { fun t6() { try { - @ while(true) { + @l while(true) { 1 if (2 > 3) { - break @ + break @l } } 5 @@ -72,10 +72,10 @@ fun t6() { fun t7() { try { - @ while(true) { + @l while(true) { 1 if (2 > 3) { - break @ + break @l } } } finally { @@ -84,11 +84,11 @@ fun t7() { } fun t8(a : Int) { - @ for (i in 1..a) { + @l for (i in 1..a) { try { 1 if (2 > 3) { - continue @ + continue @l } } finally { 2 @@ -98,10 +98,10 @@ fun t8(a : Int) { fun t9(a : Int) { try { - @ for (i in 1..a) { + @l for (i in 1..a) { 1 if (2 > 3) { - continue @ + continue @l } } 5 @@ -112,10 +112,10 @@ fun t9(a : Int) { fun t10(a : Int) { try { - @ for (i in 1..a) { + @l for (i in 1..a) { 1 if (2 > 3) { - continue @ + continue @l } } } finally { diff --git a/compiler/testData/diagnostics/tests/BreakContinue.kt b/compiler/testData/diagnostics/tests/BreakContinue.kt index 931d49f3f65..3e3424326be 100644 --- a/compiler/testData/diagnostics/tests/BreakContinue.kt +++ b/compiler/testData/diagnostics/tests/BreakContinue.kt @@ -65,9 +65,9 @@ class C { } fun containsBreakInsideLoopWithLabel(a: String?, array: Array) { - @ while(a == null) { + @l while(a == null) { for (el in array) { - break@ + break@l } } a.compareTo("2") @@ -75,10 +75,10 @@ class C { fun unresolvedBreak(a: String?, array: Array) { while(a == null) { - @ for (el in array) { + @l for (el in array) { break } - if (true) break else break@ + if (true) break else break@l } a.compareTo("2") } diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt index 3fdeb3487de..a73b71e57f2 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt @@ -9,7 +9,7 @@ fun test1() : Any = {return} fun test2() : Any = @a {return@a 1} fun test3() : Any { return } fun test4(): ()-> Unit = { return@test4 } -fun test5(): Any = @{ return@ } +fun test5(): Any = @l{ return@l } fun test6(): Any = {return 1} fun bbb() { diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.kt b/compiler/testData/diagnostics/tests/LValueAssignment.kt index 3895565bf3a..b048163c50c 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.kt @@ -60,7 +60,7 @@ fun canBe(i0: Int, j: Int) { (@label j) = 34 //repeat for j val a = A() - (@ a.a) = 3894 + (@l a.a) = 3894 } fun canBe2(j: Int) { @@ -108,7 +108,7 @@ class Test() { b += 34 a++ - (@ a)++ + (@l a)++ (a : Int)++ (a)++ } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.kt index 0f5c1340181..d9396372fc8 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.kt @@ -5,7 +5,7 @@ fun test() { fun test1() { - val x = run(@{return@ 1}) + val x = run(@l{return@l 1}) x: Int } diff --git a/compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt b/compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt new file mode 100644 index 00000000000..a46c44e2ded --- /dev/null +++ b/compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt @@ -0,0 +1,36 @@ +fun foo(a: Any?): Int { + @{ () : Unit -> + return@ + } + + @ while(a == null) { + if (true) { + break@ + } + else { + continue@ + } + } + + var b = 1 + + (@ b) = 2 + + return@ 1 +} + +open class A { + fun foo() {} +} + +class B : A() { + fun bar() { + this@.foo() + super@.foo() + } +} + +fun bar(f: () -> Unit) = f +fun test() { + bar @{} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt index 1e698add86a..870084d6945 100644 --- a/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt +++ b/compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt @@ -9,8 +9,7 @@ fun main(args : Array) { val h1 : String = --v; val i : String = !true; val j : String = @foo true; - val j1 : String = @ true; - val j2 : String = @@ true; - val k : String = -1; - val l : String = +1; + val k : String = @foo @bar true; + val l : String = -1; + val m : String = +1; } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt411.kt b/compiler/testData/diagnostics/tests/regressions/kt411.kt index 80d6d015f25..3c6ee7ef2a5 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt411.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt411.kt @@ -4,8 +4,8 @@ package kt411 fun f() { invoker( - @{ - return@ 11 // expects Function, but should expect Int + @l{ + return@l 11 // expects Function, but should expect Int } ) } @@ -13,15 +13,15 @@ fun invoker(gen : () -> Int) : Int = 0 //more tests fun t1() { - val v = @{ () : Int -> - return@ 111 + val v = @l{ () : Int -> + return@l 111 } } fun t2() : String { - val g : ()-> Int = @{ + val g : ()-> Int = @l{ if (true) { - return@ 1 + return@l 1 } return "s" } @@ -30,19 +30,19 @@ fun t2() : String { fun t3() : String { invoker( - @{ + @l{ if (true) { return@t3 "1" } else { return 2 } - return@ 0 + return@l 0 } ) invoker( - @{ (): Int -> - return@ 1 + @l{ (): Int -> + return@l 1 } ) invoker( @@ -57,8 +57,8 @@ fun t4() : Int { val h : ()-> String = @l{ return@l "a" } - val g : ()-> String = @{ () : String -> - return@ "a" + val g : ()-> String = @l{ () : String -> + return@l "a" } fun inner(): String { diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 98e081d6f6d..d814507641f 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -4656,6 +4656,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/labels/labelReferencesInsideObjectExpressions.kt"); } + @TestMetadata("labelsMustBeNamed.kt") + public void testLabelsMustBeNamed() throws Exception { + doTest("compiler/testData/diagnostics/tests/labels/labelsMustBeNamed.kt"); + } + } @TestMetadata("compiler/testData/diagnostics/tests/library") diff --git a/core/descriptors/src/org/jetbrains/jet/lang/resolve/name/Name.java b/core/descriptors/src/org/jetbrains/jet/lang/resolve/name/Name.java index be16ec88016..ea8acace7a2 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/resolve/name/Name.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/resolve/name/Name.java @@ -68,13 +68,6 @@ public final class Name implements Comparable { return new Name(name, false); } - @NotNull - public static Name identifierForLabel(@NotNull String name) { - // might be empty ('@' label) - if (name.isEmpty()) return identifierNoValidate(name); - return identifier(name); - } - @NotNull public static Name special(@NotNull String name) { if (!name.startsWith("<")) {