KT-2632 Check multi-declaraions in for-loops

#KT-2632 Fixed
This commit is contained in:
Andrey Breslav
2012-08-21 19:49:14 +04:00
parent 22974391eb
commit 5b77210c95
10 changed files with 174 additions and 1 deletions
@@ -267,6 +267,14 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
loopScope.addVariableDescriptor(variableDescriptor);
}
else {
JetMultiDeclaration multiParameter = expression.getMultiParameter();
if (multiParameter != null && loopRange != null) {
JetType elementType = expectedParameterType == null ? ErrorUtils.createErrorType("Loop range has no type") : expectedParameterType;
TransientReceiver iteratorNextAsReceiver = new TransientReceiver(elementType);
ExpressionTypingUtils.defineLocalVariablesFromMultiDeclaration(loopScope, multiParameter, iteratorNextAsReceiver, loopRange, context);
}
}
JetExpression body = expression.getBody();
if (body != null) {
@@ -0,0 +1,14 @@
class A {
fun component1() = 1
fun component2() = 1
}
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x, y) in C()) {
}
}
@@ -0,0 +1,14 @@
class A {
fun component1() = 1
fun component2() = 1.0
}
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x: Double, y: Int) in <!COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH!>C()<!>) {
}
}
@@ -0,0 +1,15 @@
class A {
<!CONFLICTING_OVERLOADS!>fun component1()<!> = 1
<!CONFLICTING_OVERLOADS!>fun component1()<!> = 1
fun component2() = 1
}
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x, y) in <!COMPONENT_FUNCTION_AMBIGUITY!>C()<!>) {
}
}
@@ -0,0 +1,13 @@
class A {
fun component1() = 1
}
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x, y) in <!COMPONENT_FUNCTION_MISSING!>C()<!>) {
}
}
@@ -0,0 +1,14 @@
class A {
}
fun A.component1() = 1
fun A.component2() = 1
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x, y) in C()) {
}
}
@@ -0,0 +1,14 @@
class A {
fun component1() = 1
fun component2() = 1.0
}
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x: Int, y: Double) in C()) {
}
}
@@ -0,0 +1,14 @@
class A {
fun component1() = 1
fun component2() = 1
}
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((<!REDECLARATION!>x<!>, <!REDECLARATION!>x<!>) in C()) {
}
}
@@ -0,0 +1,13 @@
class A {
fun component1() = 1
}
class C {
fun iterator(): Iterator<A> = null!!
}
fun test() {
for ((x) in C()) {
}
}
@@ -1113,6 +1113,60 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/declarationChecks/RedeclarationsInMultiDecl.kt");
}
@TestMetadata("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations")
public static class MultiDeclarations extends AbstractDiagnosticsTestWithEagerResolve {
public void testAllFilesPresentInMultiDeclarations() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations"), "kt", false);
}
@TestMetadata("DoubleDeclForLoop.kt")
public void testDoubleDeclForLoop() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/DoubleDeclForLoop.kt");
}
@TestMetadata("FolLoopTypeComponentTypeMismatch.kt")
public void testFolLoopTypeComponentTypeMismatch() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/FolLoopTypeComponentTypeMismatch.kt");
}
@TestMetadata("ForLoopComponentFunctionAmbiguity.kt")
public void testForLoopComponentFunctionAmbiguity() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/ForLoopComponentFunctionAmbiguity.kt");
}
@TestMetadata("ForLoopComponentFunctionMissing.kt")
public void testForLoopComponentFunctionMissing() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/ForLoopComponentFunctionMissing.kt");
}
@TestMetadata("ForLoopWithExtensions.kt")
public void testForLoopWithExtensions() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/ForLoopWithExtensions.kt");
}
@TestMetadata("ForWithExplicitTypes.kt")
public void testForWithExplicitTypes() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/ForWithExplicitTypes.kt");
}
@TestMetadata("RedeclarationInForLoop.kt")
public void testRedeclarationInForLoop() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/RedeclarationInForLoop.kt");
}
@TestMetadata("SingleDeclForLoop.kt")
public void testSingleDeclForLoop() throws Exception {
doTest("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/SingleDeclForLoop.kt");
}
}
public static Test innerSuite() {
TestSuite suite = new TestSuite("DeclarationChecks");
suite.addTestSuite(DeclarationChecks.class);
suite.addTestSuite(MultiDeclarations.class);
return suite;
}
}
@TestMetadata("compiler/testData/diagnostics/tests/extensions")
@@ -2972,7 +3026,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
suite.addTestSuite(ControlStructures.class);
suite.addTestSuite(DataFlow.class);
suite.addTestSuite(DataFlowInfoTraversal.class);
suite.addTestSuite(DeclarationChecks.class);
suite.addTest(DeclarationChecks.innerSuite());
suite.addTestSuite(Extensions.class);
suite.addTestSuite(Generics.class);
suite.addTest(IncompleteCode.innerSuite());