Fix EA-86841 and EA-79267.

(cherry picked from commit fcf9bfd)
This commit is contained in:
Stanislav Erokhin
2016-09-29 14:08:16 +03:00
committed by Stanislav Erokhin
parent c6d668e243
commit 3d7d6e4204
3 changed files with 39 additions and 22 deletions
@@ -30,8 +30,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
public abstract class AbstractClassTypeConstructor extends AbstractTypeConstructor implements TypeConstructor { public abstract class AbstractClassTypeConstructor extends AbstractTypeConstructor implements TypeConstructor {
private boolean hashCodeComputed; private int hashCode = 0;
private int hashCode;
public AbstractClassTypeConstructor(@NotNull StorageManager storageManager) { public AbstractClassTypeConstructor(@NotNull StorageManager storageManager) {
super(storageManager); super(storageManager);
@@ -39,17 +38,18 @@ public abstract class AbstractClassTypeConstructor extends AbstractTypeConstruct
@Override @Override
public final int hashCode() { public final int hashCode() {
if (!hashCodeComputed) { int currentHashCode = hashCode;
hashCodeComputed = true; if (currentHashCode != 0) return currentHashCode;
ClassifierDescriptor descriptor = getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor && hasMeaningfulFqName(descriptor)) { ClassifierDescriptor descriptor = getDeclarationDescriptor();
hashCode = DescriptorUtils.getFqName(descriptor).hashCode(); if (descriptor instanceof ClassDescriptor && hasMeaningfulFqName(descriptor)) {
} currentHashCode = DescriptorUtils.getFqName(descriptor).hashCode();
else {
hashCode = System.identityHashCode(this);
}
} }
return hashCode; else {
currentHashCode = System.identityHashCode(this);
}
hashCode = currentHashCode;
return currentHashCode;
} }
@NotNull @NotNull
@@ -220,7 +220,9 @@ public class TypeCheckingProcedure {
private boolean checkSubtypeForTheSameConstructor(@NotNull KotlinType subtype, @NotNull KotlinType supertype) { private boolean checkSubtypeForTheSameConstructor(@NotNull KotlinType subtype, @NotNull KotlinType supertype) {
TypeConstructor constructor = subtype.getConstructor(); TypeConstructor constructor = subtype.getConstructor();
assert constraints.assertEqualTypeConstructors(constructor, supertype.getConstructor()) : constructor + " is not " + supertype.getConstructor();
// this assert was moved to checker/utils.kt
//assert constraints.assertEqualTypeConstructors(constructor, supertype.getConstructor()) : constructor + " is not " + supertype.getConstructor();
List<TypeProjection> subArguments = subtype.getArguments(); List<TypeProjection> subArguments = subtype.getArguments();
List<TypeProjection> superArguments = supertype.getArguments(); List<TypeProjection> superArguments = supertype.getArguments();
@@ -16,12 +16,10 @@
package org.jetbrains.kotlin.types.checker package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitution import org.jetbrains.kotlin.resolve.calls.inference.wrapWithCapturingSubstitution
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.TypeConstructorSubstitution
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
import java.util.* import java.util.*
@@ -66,11 +64,12 @@ fun findCorrespondingSupertype(
currentPathNode = currentPathNode.previous currentPathNode = currentPathNode.previous
} }
if (!typeCheckingProcedureCallbacks.assertEqualTypeConstructors(substituted.constructor, supertypeConstructor)) { val substitutedConstructor = substituted.constructor
throw AssertionError("Type constructors should be equals!" + if (!typeCheckingProcedureCallbacks.assertEqualTypeConstructors(substitutedConstructor, supertypeConstructor)) {
"substitutedSuperType: ${DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(substituted)}, " + throw AssertionError("Type constructors should be equals!\n" +
"foundSupertype: ${DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(currentSubtype)}, " + "substitutedSuperType: ${substitutedConstructor.debugInfo()}, \n\n" +
"supertype: ${DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(supertype)}") "supertype: ${supertypeConstructor.debugInfo()} \n" +
typeCheckingProcedureCallbacks.assertEqualTypeConstructors(substitutedConstructor, supertypeConstructor))
} }
return TypeUtils.makeNullableAsSpecified(substituted, isAnyMarkedNullable) return TypeUtils.makeNullableAsSpecified(substituted, isAnyMarkedNullable)
@@ -85,3 +84,19 @@ fun findCorrespondingSupertype(
} }
private fun KotlinType.approximate() = approximateCapturedTypes(this).upper private fun KotlinType.approximate() = approximateCapturedTypes(this).upper
private fun TypeConstructor.debugInfo() = buildString {
operator fun String.unaryPlus() = appendln(this)
+ "type: ${this@debugInfo}"
+ "hashCode: ${this@debugInfo.hashCode()}"
+ "javaClass: ${this@debugInfo.javaClass.canonicalName}"
var declarationDescriptor: DeclarationDescriptor? = declarationDescriptor
while (declarationDescriptor != null) {
+ "fqName: ${DescriptorRenderer.FQ_NAMES_IN_TYPES.render(declarationDescriptor)}"
+ "javaClass: ${declarationDescriptor.javaClass.canonicalName}"
declarationDescriptor = declarationDescriptor.containingDeclaration
}
}