KT-3341 Prohibit val/var keywords for catch parameters
#KT-3341
This commit is contained in:
@@ -475,6 +475,7 @@ public interface Errors {
|
|||||||
|
|
||||||
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_LOOP_PARAMETER = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_LOOP_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_FUN_PARAMETER = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_FUN_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||||
|
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_CATCH_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
// Backing fields
|
// Backing fields
|
||||||
|
|
||||||
|
|||||||
+1
@@ -181,6 +181,7 @@ public class DefaultErrorMessages {
|
|||||||
|
|
||||||
MAP.put(VAL_OR_VAR_ON_LOOP_PARAMETER, "''{0}'' on loop parameter is not allowed", TO_STRING);
|
MAP.put(VAL_OR_VAR_ON_LOOP_PARAMETER, "''{0}'' on loop parameter is not allowed", TO_STRING);
|
||||||
MAP.put(VAL_OR_VAR_ON_FUN_PARAMETER, "''{0}'' on function parameter is not allowed", TO_STRING);
|
MAP.put(VAL_OR_VAR_ON_FUN_PARAMETER, "''{0}'' on function parameter is not allowed", TO_STRING);
|
||||||
|
MAP.put(VAL_OR_VAR_ON_CATCH_PARAMETER, "''{0}'' on catch 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);
|
||||||
|
|||||||
@@ -712,7 +712,7 @@ public class DescriptorResolver {
|
|||||||
annotationResolver.getResolvedAnnotations(parameter.getModifierList(), trace),
|
annotationResolver.getResolvedAnnotations(parameter.getModifierList(), trace),
|
||||||
JetPsiUtil.safeName(parameter.getName()),
|
JetPsiUtil.safeName(parameter.getName()),
|
||||||
type,
|
type,
|
||||||
parameter.isMutable());
|
false);
|
||||||
trace.record(BindingContext.VALUE_PARAMETER, parameter, variableDescriptor);
|
trace.record(BindingContext.VALUE_PARAMETER, parameter, variableDescriptor);
|
||||||
return variableDescriptor;
|
return variableDescriptor;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -432,6 +432,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetParameter catchParameter = catchClause.getCatchParameter();
|
JetParameter catchParameter = catchClause.getCatchParameter();
|
||||||
JetExpression catchBody = catchClause.getCatchBody();
|
JetExpression catchBody = catchClause.getCatchBody();
|
||||||
if (catchParameter != null) {
|
if (catchParameter != null) {
|
||||||
|
ASTNode valOrVarNode = catchParameter.getValOrVarNode();
|
||||||
|
if (valOrVarNode != null) {
|
||||||
|
context.trace.report(VAL_OR_VAR_ON_CATCH_PARAMETER.on(valOrVarNode.getPsi(), ((JetKeywordToken) valOrVarNode.getElementType())));
|
||||||
|
}
|
||||||
|
|
||||||
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(
|
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(
|
||||||
context.scope.getContainingDeclaration(), context.scope, catchParameter, context.trace);
|
context.scope.getContainingDeclaration(), context.scope, catchParameter, context.trace);
|
||||||
JetType throwableType = KotlinBuiltIns.getInstance().getThrowable().getDefaultType();
|
JetType throwableType = KotlinBuiltIns.getInstance().getThrowable().getDefaultType();
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fun f() {
|
||||||
|
try {
|
||||||
|
} catch (<!VAL_OR_VAR_ON_CATCH_PARAMETER!>val<!> e: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
} catch (<!VAL_OR_VAR_ON_CATCH_PARAMETER!>var<!> e: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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("valVarCatchParameter.kt")
|
||||||
|
public void testValVarCatchParameter() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/controlStructures/valVarCatchParameter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("valVarLoopParameter.kt")
|
@TestMetadata("valVarLoopParameter.kt")
|
||||||
public void testValVarLoopParameter() throws Exception {
|
public void testValVarLoopParameter() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/controlStructures/valVarLoopParameter.kt");
|
doTest("compiler/testData/diagnostics/tests/controlStructures/valVarLoopParameter.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user