From 68f0953b025a22454b4c1ac7f7e756c774038eaf Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 22 Sep 2016 12:25:49 +0300 Subject: [PATCH] Random-order variable sets are no more in use in CFG #KT-13990 Fixed (cherry picked from commit fc89385) --- .../kotlin/cfg/PseudocodeVariablesData.kt | 12 ++----- .../constructorConsistency/multipleAreNull.kt | 24 +++++++++++++ .../multipleAreNull.txt | 34 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++++ 4 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.kt create mode 100644 compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt index 75959fc66f7..5d35b69c0df 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/PseudocodeVariablesData.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.cfg import com.google.common.collect.Maps -import com.google.common.collect.Sets import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeUtil import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction @@ -25,15 +24,10 @@ import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.* import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.VariableDeclarationInstruction import org.jetbrains.kotlin.cfg.pseudocodeTraverser.Edges import org.jetbrains.kotlin.cfg.pseudocodeTraverser.TraversalOrder -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.BindingContextUtils import org.jetbrains.kotlin.resolve.BindingContextUtils.variableDescriptorForDeclaration -import org.jetbrains.kotlin.resolve.calls.tower.getFakeDescriptorForObject -import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject import java.util.Collections class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingContext: BindingContext) { @@ -56,7 +50,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon if (!includeInsideLocalDeclarations) { return getUpperLevelDeclaredVariables(pseudocode) } - val declaredVariables = Sets.newHashSet() + val declaredVariables = linkedSetOf() declaredVariables.addAll(getUpperLevelDeclaredVariables(pseudocode)) for (localFunctionDeclarationInstruction in pseudocode.localDeclarations) { @@ -76,7 +70,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon } private fun computeDeclaredVariablesForPseudocode(pseudocode: Pseudocode): Set { - val declaredVariables = Sets.newHashSet() + val declaredVariables = linkedSetOf() for (instruction in pseudocode.instructions) { if (instruction is VariableDeclarationInstruction) { val variableDeclarationElement = instruction.variableDeclarationElement @@ -217,7 +211,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon incomingEdgesData: Collection ): InitControlFlowInfo { if (incomingEdgesData.size == 1) return incomingEdgesData.single() - val variablesInScope = Sets.newHashSet() + val variablesInScope = linkedSetOf() for (edgeData in incomingEdgesData) { variablesInScope.addAll(edgeData.keys) } diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.kt b/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.kt new file mode 100644 index 00000000000..aec82faa3cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.kt @@ -0,0 +1,24 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +interface Context +class Point + +class Example { + constructor(context: Context?) + constructor(context: Context?, arg1: Int) + constructor(context: Context?, arg1: Int, arg2: Int) + constructor(context: Context?, arg1: Int, arg2: Int, arg3: Int) + + var condition: Boolean = false + private var index = newIndex(condition) + private fun newIndex(zero: Boolean) = if (zero) 0 else 1 + + private lateinit var latePoint1: Point + private lateinit var latePoint2: Point + + private val point1 = Point() + private val point2 = Point() + private val point3 = Point() + private val point4 = Point() + private var nullPoint: Point? = null +} diff --git a/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.txt b/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.txt new file mode 100644 index 00000000000..7ddac278d87 --- /dev/null +++ b/compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.txt @@ -0,0 +1,34 @@ +package + +public interface Context { + 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 +} + +public final class Example { + public constructor Example(/*0*/ context: Context?) + public constructor Example(/*0*/ context: Context?, /*1*/ arg1: kotlin.Int) + public constructor Example(/*0*/ context: Context?, /*1*/ arg1: kotlin.Int, /*2*/ arg2: kotlin.Int) + public constructor Example(/*0*/ context: Context?, /*1*/ arg1: kotlin.Int, /*2*/ arg2: kotlin.Int, /*3*/ arg3: kotlin.Int) + public final var condition: kotlin.Boolean + private final var index: kotlin.Int + private final lateinit var latePoint1: Point + private final lateinit var latePoint2: Point + private final var nullPoint: Point? + private final val point1: Point + private final val point2: Point + private final val point3: Point + private final val point4: Point + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + private final fun newIndex(/*0*/ zero: kotlin.Boolean): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class Point { + public constructor Point() + 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 +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index b57c117f776..9273c9e493d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -3213,6 +3213,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("multipleAreNull.kt") + public void testMultipleAreNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/multipleAreNull.kt"); + doTest(fileName); + } + @TestMetadata("nobacking.kt") public void testNobacking() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/constructorConsistency/nobacking.kt");