Warn on for-in-array range variable assignment in loop body

According to KT-21354, this should be a warning in 1.2 and before, and
no warning (with changed semantics) in 1.3 and later.
NB there are some false positives in this check.

 #KT-21354 In Progress
 #KT-21321 In Progress
This commit is contained in:
Dmitry Petrov
2017-12-04 13:50:28 +03:00
parent 7118a4bf80
commit 7a6f80606b
11 changed files with 335 additions and 1 deletions
@@ -1746,6 +1746,39 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ForInArrayLoop extends AbstractDiagnosticsTestWithStdLib {
public void testAllFilesPresentInForInArrayLoop() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("capturedRangeVariableAssignmentBefore13.kt")
public void testCapturedRangeVariableAssignmentBefore13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/capturedRangeVariableAssignmentBefore13.kt");
doTest(fileName);
}
@TestMetadata("rangeLocalDelegatedPropertyAssignmentBefore13.kt")
public void testRangeLocalDelegatedPropertyAssignmentBefore13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeLocalDelegatedPropertyAssignmentBefore13.kt");
doTest(fileName);
}
@TestMetadata("rangeVariableAssignment13.kt")
public void testRangeVariableAssignment13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignment13.kt");
doTest(fileName);
}
@TestMetadata("rangeVariableAssignmentBefore13.kt")
public void testRangeVariableAssignmentBefore13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignmentBefore13.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/functionLiterals")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1746,6 +1746,39 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ForInArrayLoop extends AbstractDiagnosticsTestWithStdLibUsingJavac {
public void testAllFilesPresentInForInArrayLoop() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("capturedRangeVariableAssignmentBefore13.kt")
public void testCapturedRangeVariableAssignmentBefore13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/capturedRangeVariableAssignmentBefore13.kt");
doTest(fileName);
}
@TestMetadata("rangeLocalDelegatedPropertyAssignmentBefore13.kt")
public void testRangeLocalDelegatedPropertyAssignmentBefore13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeLocalDelegatedPropertyAssignmentBefore13.kt");
doTest(fileName);
}
@TestMetadata("rangeVariableAssignment13.kt")
public void testRangeVariableAssignment13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignment13.kt");
doTest(fileName);
}
@TestMetadata("rangeVariableAssignmentBefore13.kt")
public void testRangeVariableAssignmentBefore13() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/forInArrayLoop/rangeVariableAssignmentBefore13.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/functionLiterals")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)