mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 00:21:47 +00:00
Kotlinc source’s file DescriptorUtils.kt demonstarted non-deterministic insertion of checkExpressionValueIsNotNull for value returned by CallableDescriptor::getOriginal(). It was difficult to reproduce this behavior on ф smaller example, but I added a test which was failing once in 5-10 times while I was testing manually. I believe this bug is close to KT-23704. This PR addresses non-determinism to a degree when I can run 120 Compilations with './gradlew dist' and get same classes in all jars in 'dist'. NOTE that thew fact that insertion of checkExpressionValueIsNotNull may depend on order of the types seems suspicios. This CL only addresses non-determinism part, but I believe it’s worth looking into this more from semantics point of view.
110 lines
2.6 KiB
Kotlin
Vendored
110 lines
2.6 KiB
Kotlin
Vendored
// FILE: test/DeclarationDescriptor.java
|
|
|
|
package test;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.Collection;
|
|
|
|
public interface DeclarationDescriptor {
|
|
@NotNull
|
|
DeclarationDescriptor getOriginal();
|
|
|
|
@Nullable
|
|
DeclarationDescriptor getContainingDeclaration();
|
|
}
|
|
|
|
// FILE: test/DeclarationDescriptorWithVisibility.java
|
|
package test;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.Collection;
|
|
|
|
public interface DeclarationDescriptorWithVisibility extends DeclarationDescriptor {
|
|
}
|
|
|
|
// FILE: test/DeclarationDescriptorWithSource.java
|
|
package test;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.Collection;
|
|
|
|
public interface DeclarationDescriptorWithSource extends DeclarationDescriptor {
|
|
@Override
|
|
@NotNull
|
|
DeclarationDescriptorWithSource getOriginal();
|
|
}
|
|
|
|
// FILE: test/DeclarationDescriptorNonRoot.java
|
|
package test;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.Collection;
|
|
|
|
public interface DeclarationDescriptorNonRoot extends DeclarationDescriptorWithSource {
|
|
}
|
|
|
|
// FILE: test/CallableDescriptor.java
|
|
package test;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.Collection;
|
|
|
|
public interface CallableDescriptor extends DeclarationDescriptorWithVisibility, DeclarationDescriptorNonRoot {
|
|
@NotNull
|
|
@Override
|
|
CallableDescriptor getOriginal();
|
|
|
|
@NotNull
|
|
Collection<? extends CallableDescriptor> getOverriddenDescriptors();
|
|
}
|
|
|
|
// FILE: test/k.kt
|
|
package test
|
|
|
|
fun <D : CallableDescriptor> D.overriddenTreeUniqueAsSequenceA(useOriginal: Boolean): Sequence<D> {
|
|
val set = hashSetOf<D>()
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
fun D.doBuildOverriddenTreeAsSequence(): Sequence<D> {
|
|
return with(if (useOriginal) original as D else this) {
|
|
if (original in set)
|
|
emptySequence()
|
|
else {
|
|
emptySequence()
|
|
}
|
|
}
|
|
}
|
|
|
|
return doBuildOverriddenTreeAsSequence()
|
|
}
|
|
|
|
fun <D : CallableDescriptor> D.overriddenTreeUniqueAsSequenceB(useOriginal: Boolean): Sequence<D> {
|
|
val set = hashSetOf<D>()
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
fun D.doBuildOverriddenTreeAsSequence(): Sequence<D> {
|
|
return with(if (useOriginal) original as D else this) {
|
|
if (original in set)
|
|
emptySequence()
|
|
else {
|
|
emptySequence()
|
|
}
|
|
}
|
|
}
|
|
|
|
return doBuildOverriddenTreeAsSequence()
|
|
}
|
|
|
|
// @KKt.class:
|
|
// 0 checkExpressionValueIsNotNull
|