Fix typechecker in case of "for ((a, b) in) { }"

Fixes NDFDE
This commit is contained in:
Pavel V. Talanov
2016-03-01 20:03:35 +03:00
parent 363d545bd5
commit 1affb05b7b
6 changed files with 42 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -414,7 +414,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
}
else {
KtDestructuringDeclaration multiParameter = expression.getDestructuringParameter();
if (multiParameter != null && loopRange != null) {
if (multiParameter != null) {
KotlinType elementType = expectedParameterType == null ? ErrorUtils.createErrorType("Loop range has no type") : expectedParameterType;
TransientReceiver iteratorNextAsReceiver = new TransientReceiver(elementType);
components.annotationResolver.resolveAnnotationsWithArguments(loopScope, multiParameter.getModifierList(), context.trace);
@@ -0,0 +1,14 @@
fun useDeclaredVariables() {
for ((a, b)<!SYNTAX!><!>) {
<!UNUSED_EXPRESSION, DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>
<!UNUSED_EXPRESSION, DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>b<!>
}
}
fun checkersShouldRun() {
for ((@A a, <!UNDERSCORE_IS_RESERVED!>_<!>)<!SYNTAX!><!>) {
}
}
annotation class A
@@ -0,0 +1,11 @@
package
public fun checkersShouldRun(): kotlin.Unit
public fun useDeclaredVariables(): kotlin.Unit
public final annotation class A : kotlin.Annotation {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -4493,6 +4493,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("ForLoopMissingLoopParameter.kt")
public void testForLoopMissingLoopParameter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/ForLoopMissingLoopParameter.kt");
doTest(fileName);
}
@TestMetadata("ForLoopWithExtensions.kt")
public void testForLoopWithExtensions() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/declarationChecks/multiDeclarations/ForLoopWithExtensions.kt");
@@ -0,0 +1,3 @@
fun main() {
for ((i, j)<error>)</error> {}
}
@@ -472,6 +472,12 @@ public class PsiCheckerTestGenerated extends AbstractPsiCheckerTest {
doTest(fileName);
}
@TestMetadata("DescructuringDeclarationInForLoop.kt")
public void testDescructuringDeclarationInForLoop() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/regression/DescructuringDeclarationInForLoop.kt");
doTest(fileName);
}
@TestMetadata("DoubleDefine.kt")
public void testDoubleDefine() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/regression/DoubleDefine.kt");