Fix for KT-19188
Fixes nondeterministic Default Method Order under existance of generic type parameters. SubstitutingScope did not respect source code method order by not using a LinkedHashSet
This commit is contained in:
committed by
Denis Zharkov
parent
8257e14055
commit
f961f33f9d
@@ -107,6 +107,31 @@ class MethodOrderTest: CodegenTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
fun testDeterministicDefaultMethodImplOrder() {
|
||||
doTest(
|
||||
"""
|
||||
interface Base<K, V> {
|
||||
fun getSize(): Int = 5
|
||||
fun size(): Int = getSize()
|
||||
fun getKeys(): Int = 4
|
||||
fun keySet() = getKeys()
|
||||
fun getEntries(): Int = 3
|
||||
fun entrySet() = getEntries()
|
||||
fun getValues(): Int = 2
|
||||
fun values() = getValues()
|
||||
|
||||
fun removeEldestEntry(eldest: Any?): Boolean
|
||||
}
|
||||
|
||||
class MinMap<K, V> : Base<K, V> {
|
||||
override fun removeEldestEntry(eldest: Any?) = true
|
||||
}
|
||||
""",
|
||||
"MinMap",
|
||||
listOf("removeEldestEntry(Ljava/lang/Object;)Z", "<init>()V", "getSize()I", "size()I", "getKeys()I", "keySet()I", "getEntries()I", "entrySet()I", "getValues()I", "values()I")
|
||||
)
|
||||
}
|
||||
|
||||
private fun doTest(sourceText: String, classSuffix: String, expectedOrder: List<String>) {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY)
|
||||
myFiles = CodegenTestFiles.create("file.kt", sourceText, myEnvironment!!.project)
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitution
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.newHashSetWithExpectedSize
|
||||
import org.jetbrains.kotlin.utils.newLinkedHashSetWithExpectedSize
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.util.*
|
||||
|
||||
@@ -60,7 +60,7 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
|
||||
if (substitutor.isEmpty) return descriptors
|
||||
if (descriptors.isEmpty()) return descriptors
|
||||
|
||||
val result = newHashSetWithExpectedSize<D>(descriptors.size)
|
||||
val result = newLinkedHashSetWithExpectedSize<D>(descriptors.size)
|
||||
for (descriptor in descriptors) {
|
||||
val substitute = substitute(descriptor)
|
||||
result.add(substitute)
|
||||
|
||||
Reference in New Issue
Block a user