KT-2632 Check multi-declaraions in for-loops
#KT-2632 Fixed
This commit is contained in:
+8
@@ -267,6 +267,14 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
loopScope.addVariableDescriptor(variableDescriptor);
|
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();
|
JetExpression body = expression.getBody();
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
|
|||||||
+14
@@ -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()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -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()<!>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -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()<!>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -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()<!>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -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()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -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()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -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()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -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");
|
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")
|
@TestMetadata("compiler/testData/diagnostics/tests/extensions")
|
||||||
@@ -2972,7 +3026,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
suite.addTestSuite(ControlStructures.class);
|
suite.addTestSuite(ControlStructures.class);
|
||||||
suite.addTestSuite(DataFlow.class);
|
suite.addTestSuite(DataFlow.class);
|
||||||
suite.addTestSuite(DataFlowInfoTraversal.class);
|
suite.addTestSuite(DataFlowInfoTraversal.class);
|
||||||
suite.addTestSuite(DeclarationChecks.class);
|
suite.addTest(DeclarationChecks.innerSuite());
|
||||||
suite.addTestSuite(Extensions.class);
|
suite.addTestSuite(Extensions.class);
|
||||||
suite.addTestSuite(Generics.class);
|
suite.addTestSuite(Generics.class);
|
||||||
suite.addTest(IncompleteCode.innerSuite());
|
suite.addTest(IncompleteCode.innerSuite());
|
||||||
|
|||||||
Reference in New Issue
Block a user