Generate parse error on label without name '@'
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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<DeclarationDescriptor> declarationsByLabel = context.scope.getDeclarationsByLabel(labelName);
|
||||
int size = declarationsByLabel.size();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user