KT-3182 Prohibit val/var keywords at for-loop counter.
#KT-3182 fixed
This commit is contained in:
@@ -473,6 +473,8 @@ public interface Errors {
|
|||||||
|
|
||||||
DiagnosticFactory3<JetExpression, DeclarationDescriptor, Visibility, DeclarationDescriptor> INVISIBLE_SETTER = DiagnosticFactory3.create(ERROR);
|
DiagnosticFactory3<JetExpression, DeclarationDescriptor, Visibility, DeclarationDescriptor> INVISIBLE_SETTER = DiagnosticFactory3.create(ERROR);
|
||||||
|
|
||||||
|
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_LOOP_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
// Backing fields
|
// Backing fields
|
||||||
|
|
||||||
SimpleDiagnosticFactory<JetElement> NO_BACKING_FIELD_ABSTRACT_PROPERTY = SimpleDiagnosticFactory.create(ERROR);
|
SimpleDiagnosticFactory<JetElement> NO_BACKING_FIELD_ABSTRACT_PROPERTY = SimpleDiagnosticFactory.create(ERROR);
|
||||||
|
|||||||
+2
@@ -179,6 +179,8 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME);
|
MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME);
|
||||||
MAP.put(VARIABLE_EXPECTED, "Variable expected");
|
MAP.put(VARIABLE_EXPECTED, "Variable expected");
|
||||||
|
|
||||||
|
MAP.put(VAL_OR_VAR_ON_LOOP_PARAMETER, "''{0}'' on loop parameter is not allowed", TO_STRING);
|
||||||
|
|
||||||
MAP.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER,
|
MAP.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER,
|
||||||
"This property has a custom setter, so initialization using backing field required", NAME);
|
"This property has a custom setter, so initialization using backing field required", NAME);
|
||||||
MAP.put(INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER,
|
MAP.put(INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER,
|
||||||
|
|||||||
+8
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.types.expressions;
|
package org.jetbrains.jet.lang.types.expressions;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
@@ -44,6 +45,8 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
|||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
|
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -311,6 +314,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType expectedParameterType,
|
JetType expectedParameterType,
|
||||||
ExpressionTypingContext context
|
ExpressionTypingContext context
|
||||||
) {
|
) {
|
||||||
|
ASTNode valOrVarNode = loopParameter.getValOrVarNode();
|
||||||
|
if (valOrVarNode != null) {
|
||||||
|
context.trace.report(VAL_OR_VAR_ON_LOOP_PARAMETER.on(valOrVarNode.getPsi(), ((JetKeywordToken) valOrVarNode.getElementType())));
|
||||||
|
}
|
||||||
|
|
||||||
JetTypeReference typeReference = loopParameter.getTypeReference();
|
JetTypeReference typeReference = loopParameter.getTypeReference();
|
||||||
VariableDescriptor variableDescriptor;
|
VariableDescriptor variableDescriptor;
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fun f() {
|
||||||
|
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>val<!> i in 1..4) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (<!VAL_OR_VAR_ON_LOOP_PARAMETER!>var<!> i in 1..4) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1045,6 +1045,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/controlStructures/tryReturnType.kt");
|
doTest("compiler/testData/diagnostics/tests/controlStructures/tryReturnType.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("valVarLoopParameter.kt")
|
||||||
|
public void testValVarLoopParameter() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/controlStructures/valVarLoopParameter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("when.kt234.kt973.kt")
|
@TestMetadata("when.kt234.kt973.kt")
|
||||||
public void testWhen_kt234_kt973() throws Exception {
|
public void testWhen_kt234_kt973() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt");
|
doTest("compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user