Smart casts for local variables not captured in a closure and not changed in a loop, see #KT-3175.

isLocalVariable added. Assignment / initialization analysis.
Control whether a variable is changed in a loop at the beginning and at the end of the loop.
Control whether a variable is captured in a closure. #KT-3175  Fixed. #KT-2266  Fixed.
Tests for variable null safety and for variables is/as operations.
Loop / closure / variable property tests are included.
Old tests changed in accordance with KT-3175. In particular, all three of testSmartcastImpossible were fixed.
This commit is contained in:
Mikhail Glukhikh
2015-03-24 17:03:01 +03:00
parent e4b1046a54
commit d5aed62410
126 changed files with 1655 additions and 71 deletions
@@ -11450,6 +11450,324 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/tests/smartCasts/variables")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Variables extends AbstractJetDiagnosticsTest {
public void testAllFilesPresentInVariables() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/variables"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("assignment.kt")
public void testAssignment() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/assignment.kt");
doTest(fileName);
}
@TestMetadata("doWhileWithMiddleBreak.kt")
public void testDoWhileWithMiddleBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/doWhileWithMiddleBreak.kt");
doTest(fileName);
}
@TestMetadata("ifElseBlockInsideDoWhile.kt")
public void testIfElseBlockInsideDoWhile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhile.kt");
doTest(fileName);
}
@TestMetadata("ifElseBlockInsideDoWhileWithBreak.kt")
public void testIfElseBlockInsideDoWhileWithBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/ifElseBlockInsideDoWhileWithBreak.kt");
doTest(fileName);
}
@TestMetadata("ifVarIs.kt")
public void testIfVarIs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIs.kt");
doTest(fileName);
}
@TestMetadata("ifVarIsAnd.kt")
public void testIfVarIsAnd() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsAnd.kt");
doTest(fileName);
}
@TestMetadata("ifVarIsChanged.kt")
public void testIfVarIsChanged() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/ifVarIsChanged.kt");
doTest(fileName);
}
@TestMetadata("infix.kt")
public void testInfix() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/infix.kt");
doTest(fileName);
}
@TestMetadata("initialization.kt")
public void testInitialization() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/initialization.kt");
doTest(fileName);
}
@TestMetadata("property.kt")
public void testProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/property.kt");
doTest(fileName);
}
@TestMetadata("propertyNotNeeded.kt")
public void testPropertyNotNeeded() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/propertyNotNeeded.kt");
doTest(fileName);
}
@TestMetadata("propertySubtype.kt")
public void testPropertySubtype() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtype.kt");
doTest(fileName);
}
@TestMetadata("propertySubtypeInMember.kt")
public void testPropertySubtypeInMember() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMember.kt");
doTest(fileName);
}
@TestMetadata("propertySubtypeInMemberCheck.kt")
public void testPropertySubtypeInMemberCheck() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/propertySubtypeInMemberCheck.kt");
doTest(fileName);
}
@TestMetadata("varAsUse.kt")
public void testVarAsUse() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/varAsUse.kt");
doTest(fileName);
}
@TestMetadata("varChangedInLoop.kt")
public void testVarChangedInLoop() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/varChangedInLoop.kt");
doTest(fileName);
}
@TestMetadata("varNotChangedInLoop.kt")
public void testVarNotChangedInLoop() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/varNotChangedInLoop.kt");
doTest(fileName);
}
@TestMetadata("whileTrue.kt")
public void testWhileTrue() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/whileTrue.kt");
doTest(fileName);
}
@TestMetadata("whileWithBreak.kt")
public void testWhileWithBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/whileWithBreak.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Varnotnull extends AbstractJetDiagnosticsTest {
public void testAllFilesPresentInVarnotnull() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/varnotnull"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("assignment.kt")
public void testAssignment() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.kt");
doTest(fileName);
}
@TestMetadata("doWhileWithBreak.kt")
public void testDoWhileWithBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithBreak.kt");
doTest(fileName);
}
@TestMetadata("doWhileWithMiddleBreak.kt")
public void testDoWhileWithMiddleBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/doWhileWithMiddleBreak.kt");
doTest(fileName);
}
@TestMetadata("forEach.kt")
public void testForEach() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEach.kt");
doTest(fileName);
}
@TestMetadata("forEachWithBreak.kt")
public void testForEachWithBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithBreak.kt");
doTest(fileName);
}
@TestMetadata("forEachWithContinue.kt")
public void testForEachWithContinue() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEachWithContinue.kt");
doTest(fileName);
}
@TestMetadata("ifVarNotNull.kt")
public void testIfVarNotNull() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNull.kt");
doTest(fileName);
}
@TestMetadata("ifVarNotNullAnd.kt")
public void testIfVarNotNullAnd() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNotNullAnd.kt");
doTest(fileName);
}
@TestMetadata("ifVarNullElse.kt")
public void testIfVarNullElse() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullElse.kt");
doTest(fileName);
}
@TestMetadata("ifVarNullReturn.kt")
public void testIfVarNullReturn() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/ifVarNullReturn.kt");
doTest(fileName);
}
@TestMetadata("inference.kt")
public void testInference() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/inference.kt");
doTest(fileName);
}
@TestMetadata("infiniteWhileWithBreak.kt")
public void testInfiniteWhileWithBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/infiniteWhileWithBreak.kt");
doTest(fileName);
}
@TestMetadata("infix.kt")
public void testInfix() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/infix.kt");
doTest(fileName);
}
@TestMetadata("initialization.kt")
public void testInitialization() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/initialization.kt");
doTest(fileName);
}
@TestMetadata("iterations.kt")
public void testIterations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/iterations.kt");
doTest(fileName);
}
@TestMetadata("nestedDoWhile.kt")
public void testNestedDoWhile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedDoWhile.kt");
doTest(fileName);
}
@TestMetadata("nestedLoops.kt")
public void testNestedLoops() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedLoops.kt");
doTest(fileName);
}
@TestMetadata("nestedWhile.kt")
public void testNestedWhile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/nestedWhile.kt");
doTest(fileName);
}
@TestMetadata("unnecessary.kt")
public void testUnnecessary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessary.kt");
doTest(fileName);
}
@TestMetadata("unnecessaryWithBranch.kt")
public void testUnnecessaryWithBranch() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithBranch.kt");
doTest(fileName);
}
@TestMetadata("unnecessaryWithMap.kt")
public void testUnnecessaryWithMap() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/unnecessaryWithMap.kt");
doTest(fileName);
}
@TestMetadata("varCapturedInClosure.kt")
public void testVarCapturedInClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInClosure.kt");
doTest(fileName);
}
@TestMetadata("varCapturedInInlineClosure.kt")
public void testVarCapturedInInlineClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInInlineClosure.kt");
doTest(fileName);
}
@TestMetadata("varCapturedInSafeClosure.kt")
public void testVarCapturedInSafeClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCapturedInSafeClosure.kt");
doTest(fileName);
}
@TestMetadata("varChangedInLoop.kt")
public void testVarChangedInLoop() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varChangedInLoop.kt");
doTest(fileName);
}
@TestMetadata("varCheck.kt")
public void testVarCheck() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varCheck.kt");
doTest(fileName);
}
@TestMetadata("varIntNull.kt")
public void testVarIntNull() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt");
doTest(fileName);
}
@TestMetadata("varNotChangedInLoop.kt")
public void testVarNotChangedInLoop() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNotChangedInLoop.kt");
doTest(fileName);
}
@TestMetadata("varNull.kt")
public void testVarNull() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/varNull.kt");
doTest(fileName);
}
@TestMetadata("whileTrue.kt")
public void testWhileTrue() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileTrue.kt");
doTest(fileName);
}
@TestMetadata("whileWithBreak.kt")
public void testWhileWithBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/whileWithBreak.kt");
doTest(fileName);
}
}
}
@TestMetadata("compiler/testData/diagnostics/tests/substitutions")