TypeConstructor's equality for classes relies on FqNames
This is needed because different modules/libraries may define classes with the same FqNames, which may be identical or slightly different. Such classes must be considered equal, because your dependencies may rely on different packagings of the same codebase, and the classes there will be distinct though identical (think intellij-core vs idea-full).
This commit is contained in:
+2
-1
@@ -45,6 +45,7 @@ import org.jetbrains.jet.lang.resolve.lazy.data.SyntheticClassObjectInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.types.AbstractClassTypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -468,7 +469,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
}
|
||||
|
||||
private class LazyClassTypeConstructor implements LazyEntity, TypeConstructor {
|
||||
private class LazyClassTypeConstructor extends AbstractClassTypeConstructor implements LazyEntity {
|
||||
private final NotNullLazyValue<Supertypes> supertypes = resolveSession.getStorageManager().createLazyValueWithPostCompute(
|
||||
new Function0<Supertypes>() {
|
||||
@Override
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A
|
||||
public class M1 {
|
||||
public val a: A = A()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A<T>
|
||||
|
||||
public fun foo(a: A<Int>) {
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
foo(<!TYPE_MISMATCH!>M1().a<!>)
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A<T>
|
||||
public class M1 {
|
||||
public val a: A<Int> = A<Int>()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A
|
||||
|
||||
public fun foo(a: A) {
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
foo(<!TYPE_MISMATCH!>M1().a<!>)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A
|
||||
public class B {
|
||||
public val a: A = A()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A {
|
||||
val x = 1
|
||||
}
|
||||
|
||||
public fun foo(a: A) {
|
||||
a.x + 1
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
foo(B().a)
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A {
|
||||
public class B
|
||||
public object C
|
||||
class object {
|
||||
public class D {
|
||||
public object E
|
||||
}
|
||||
public class G
|
||||
}
|
||||
|
||||
public inner class F
|
||||
}
|
||||
|
||||
public class M1 {
|
||||
public val a: A = A()
|
||||
public val b: A.B = A.B()
|
||||
public val c: A.C = A.C
|
||||
public val d: A.D = A.D()
|
||||
public val e: A.D.E = A.D.E
|
||||
public val f: A.F = A().F()
|
||||
public val g: A.G = A.G()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A {
|
||||
public class B
|
||||
public class C
|
||||
class object {
|
||||
public class D {
|
||||
public class E
|
||||
}
|
||||
}
|
||||
public class G
|
||||
public inner class F
|
||||
}
|
||||
|
||||
public fun a(p: A) {}
|
||||
public fun b(p: A.B) {}
|
||||
public fun c(p: A.C) {}
|
||||
public fun d(p: A.D) {}
|
||||
public fun e(p: A.D.E) {}
|
||||
public fun f(p: A.F) {}
|
||||
public fun g(p: A.G) {}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test(m1: M1) {
|
||||
a(m1.a)
|
||||
b(m1.b)
|
||||
c(m1.c)
|
||||
d(m1.d)
|
||||
e(m1.e)
|
||||
f(m1.f)
|
||||
g(m1.g)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public trait A
|
||||
public class B : A
|
||||
public class M1 {
|
||||
public val b: B = B()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public trait A
|
||||
|
||||
public fun foo(a: A) {
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
foo(M1().b)
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A<X, Y>
|
||||
public class M1 {
|
||||
public val a: A<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!> = A<Int, Int>()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A<X, Y>
|
||||
|
||||
public fun foo(a: A<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!>) {
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
foo(M1().<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>a<!>)
|
||||
foo(1) // error type on the declaration site
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public trait A<T>
|
||||
public trait C
|
||||
public trait D<T>
|
||||
public class B : A<Int>, C, D<Int>
|
||||
public class M1 {
|
||||
public val b: B = B()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public trait A
|
||||
public trait C<T>
|
||||
public trait D<T>
|
||||
|
||||
public fun a(a: A) {
|
||||
}
|
||||
|
||||
public fun c(c: C<Int>) {
|
||||
}
|
||||
|
||||
public fun d(d: D<Int>) {
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
a(<!TYPE_MISMATCH!>M1().b<!>) // Type arguments do not match
|
||||
c(<!TYPE_MISMATCH!>M1().b<!>) // Type arguments do not match
|
||||
d(M1().b) // Type arguments do match
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A
|
||||
public class B {
|
||||
public val a: A = A()
|
||||
}
|
||||
|
||||
// MODULE: m2(m1)
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a: A = B().a
|
||||
a.foo()
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A
|
||||
public class B {
|
||||
public val a: A = A()
|
||||
}
|
||||
|
||||
// MODULE: m2(m1)
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a = B().a
|
||||
a.<!UNRESOLVED_REFERENCE!>foo<!>()
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A {
|
||||
public fun m1() {}
|
||||
}
|
||||
public class M1 {
|
||||
public val a: A = A()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A {
|
||||
public fun m2() {}
|
||||
}
|
||||
|
||||
public class M2 {
|
||||
public val a: A = A()
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test(a: A) {
|
||||
a.m1()
|
||||
|
||||
M1().a.m1()
|
||||
|
||||
M2().a.m2()
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A
|
||||
public class B {
|
||||
public val a: A = A()
|
||||
}
|
||||
|
||||
// MODULE: m2(m1)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
class A
|
||||
|
||||
fun test() {
|
||||
val a: A = <!TYPE_MISMATCH!>B().a<!>
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// MODULE: m1
|
||||
// FILE: a.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A<T>
|
||||
public class M1 {
|
||||
public val a: A<Int> = A()
|
||||
}
|
||||
|
||||
// MODULE: m2
|
||||
// FILE: b.kt
|
||||
|
||||
package p
|
||||
|
||||
public class A<T>
|
||||
|
||||
public fun foo(a: A<Int>) {
|
||||
}
|
||||
|
||||
// MODULE: m3(m1, m2)
|
||||
// FILE: b.kt
|
||||
|
||||
import p.*
|
||||
|
||||
fun test() {
|
||||
foo(M1().a)
|
||||
}
|
||||
@@ -4687,6 +4687,7 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/multimodule")
|
||||
@InnerTestClasses({Multimodule.DuplicateClass.class})
|
||||
public static class Multimodule extends AbstractJetDiagnosticsTest {
|
||||
public void testAllFilesPresentInMultimodule() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/tests/multimodule"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
@@ -4702,6 +4703,80 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/packagePrivate.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/multimodule/duplicateClass")
|
||||
public static class DuplicateClass extends AbstractJetDiagnosticsTest {
|
||||
public void testAllFilesPresentInDuplicateClass() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/diagnostics/tests/multimodule/duplicateClass"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("differentGenericArguments.kt")
|
||||
public void testDifferentGenericArguments() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArguments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("differentGenericArgumentsReversed.kt")
|
||||
public void testDifferentGenericArgumentsReversed() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/differentGenericArgumentsReversed.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("duplicateClass.kt")
|
||||
public void testDuplicateClass() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("duplicateNestedClasses.kt")
|
||||
public void testDuplicateNestedClasses() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateNestedClasses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("duplicateSuperClass.kt")
|
||||
public void testDuplicateSuperClass() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/duplicateSuperClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericArgumentNumberMismatch.kt")
|
||||
public void testGenericArgumentNumberMismatch() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericArgumentNumberMismatch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericSuperClass.kt")
|
||||
public void testGenericSuperClass() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/genericSuperClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inTheSameModuleWithUsage.kt")
|
||||
public void testInTheSameModuleWithUsage() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsage.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inTheSameModuleWithUsageNoTypeAnnotation.kt")
|
||||
public void testInTheSameModuleWithUsageNoTypeAnnotation() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/inTheSameModuleWithUsageNoTypeAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("members.kt")
|
||||
public void testMembers() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/members.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sameClassNameDifferentPackages.kt")
|
||||
public void testSameClassNameDifferentPackages() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameClassNameDifferentPackages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("sameGenericArguments.kt")
|
||||
public void testSameGenericArguments() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/multimodule/duplicateClass/sameGenericArguments.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Multimodule");
|
||||
suite.addTestSuite(Multimodule.class);
|
||||
suite.addTestSuite(DuplicateClass.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/namedArguments")
|
||||
@@ -7094,7 +7169,7 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
suite.addTest(Jdk_annotations.innerSuite());
|
||||
suite.addTestSuite(Labels.class);
|
||||
suite.addTestSuite(Library.class);
|
||||
suite.addTestSuite(Multimodule.class);
|
||||
suite.addTest(Multimodule.innerSuite());
|
||||
suite.addTestSuite(NamedArguments.class);
|
||||
suite.addTestSuite(NullabilityAndAutoCasts.class);
|
||||
suite.addTestSuite(NullableTypes.class);
|
||||
|
||||
+2
-1
@@ -52,6 +52,7 @@ import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaClassStaticsPackageFragmentDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames
|
||||
import org.jetbrains.jet.lang.types.AbstractClassTypeConstructor
|
||||
|
||||
class LazyJavaClassDescriptor(
|
||||
private val outerC: LazyJavaResolverContextWithTypes,
|
||||
@@ -188,7 +189,7 @@ class LazyJavaClassDescriptor(
|
||||
|
||||
override fun toString() = "lazy java class $fqName"
|
||||
|
||||
private inner class LazyJavaClassTypeConstructor : TypeConstructor {
|
||||
private inner class LazyJavaClassTypeConstructor : AbstractClassTypeConstructor() {
|
||||
|
||||
private val _parameters = c.storageManager.createLazyValue {
|
||||
jClass.getTypeParameters().map({
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.descriptors.impl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -49,7 +48,7 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
|
||||
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name);
|
||||
this.modality = modality;
|
||||
|
||||
this.typeConstructor = new TypeConstructorImpl(this, Annotations.EMPTY, false, getName().asString(),
|
||||
this.typeConstructor = TypeConstructorImpl.createForClass(this, Annotations.EMPTY, false, getName().asString(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(), supertypes);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
this.kind = kind;
|
||||
|
||||
this.typeConstructor =
|
||||
new TypeConstructorImpl(this, getAnnotations(), true, "enum entry", Collections.<TypeParameterDescriptor>emptyList(),
|
||||
TypeConstructorImpl.createForClass(this, getAnnotations(), true, "enum entry", Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singleton(supertype));
|
||||
|
||||
this.scope = new EnumEntryScope(storageManager);
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
|
||||
supertypes.add(substitutor.substitute(supertype, Variance.INVARIANT));
|
||||
}
|
||||
|
||||
typeConstructor = new TypeConstructorImpl(
|
||||
typeConstructor = TypeConstructorImpl.createForClass(
|
||||
this,
|
||||
originalTypeConstructor.getAnnotations(),
|
||||
originalTypeConstructor.isFinal(),
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase implements Class
|
||||
|
||||
public void createTypeConstructor() {
|
||||
assert typeConstructor == null : typeConstructor;
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this.typeConstructor = TypeConstructorImpl.createForClass(
|
||||
this,
|
||||
Annotations.EMPTY, // TODO : pass annotations from the class?
|
||||
!getModality().isOverridable(),
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
||||
@Override
|
||||
protected TypeConstructor createTypeConstructor() {
|
||||
// TODO: Should we actually pass the annotations on to the type constructor?
|
||||
return new TypeConstructorImpl(
|
||||
return TypeConstructorImpl.createForTypeParameter(
|
||||
this,
|
||||
getAnnotations(),
|
||||
false,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
|
||||
public abstract class AbstractClassTypeConstructor implements TypeConstructor {
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return hashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
public boolean equals(Object obj) {
|
||||
return equals(this, obj);
|
||||
}
|
||||
|
||||
public static boolean equals(@NotNull TypeConstructor me, Object other) {
|
||||
if (!(other instanceof TypeConstructor)) return false;
|
||||
ClassifierDescriptor myDescriptor = me.getDeclarationDescriptor();
|
||||
ClassifierDescriptor otherDescriptor = ((TypeConstructor) other).getDeclarationDescriptor();
|
||||
|
||||
if (myDescriptor == otherDescriptor) return true;
|
||||
|
||||
if (myDescriptor instanceof ClassDescriptor && otherDescriptor instanceof ClassDescriptor) {
|
||||
FqNameUnsafe otherFqName = DescriptorUtils.getFqName(otherDescriptor);
|
||||
FqNameUnsafe myFqName = DescriptorUtils.getFqName(myDescriptor);
|
||||
return myFqName.equals(otherFqName);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int hashCode(@NotNull TypeConstructor me) {
|
||||
if (me.getDeclarationDescriptor() instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) me.getDeclarationDescriptor();
|
||||
return DescriptorUtils.getFqName(classDescriptor).hashCode();
|
||||
}
|
||||
return System.identityHashCode(me);
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ public class ErrorUtils {
|
||||
|
||||
@NotNull
|
||||
private static TypeConstructor createErrorTypeConstructorWithCustomDebugName(@NotNull String debugName) {
|
||||
return new TypeConstructorImpl(ERROR_CLASS, Annotations.EMPTY, false, debugName,
|
||||
return TypeConstructorImpl.createForClass(ERROR_CLASS, Annotations.EMPTY, false, debugName,
|
||||
Collections.<TypeParameterDescriptorImpl>emptyList(),
|
||||
Collections.singleton(KotlinBuiltIns.getInstance().getAnyType()));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
|
||||
@@ -28,16 +29,61 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class TypeConstructorImpl extends AnnotatedImpl implements TypeConstructor {
|
||||
public abstract class TypeConstructorImpl extends AnnotatedImpl implements TypeConstructor {
|
||||
|
||||
@NotNull
|
||||
public static TypeConstructorImpl createForClass(
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isFinal,
|
||||
@NotNull String debugName,
|
||||
@NotNull List<? extends TypeParameterDescriptor> parameters,
|
||||
@NotNull Collection<JetType> supertypes
|
||||
) {
|
||||
return new TypeConstructorImpl(classDescriptor, annotations, isFinal, debugName, parameters, supertypes) {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return AbstractClassTypeConstructor.hashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
|
||||
public boolean equals(Object obj) {
|
||||
return AbstractClassTypeConstructor.equals(this, obj);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TypeConstructorImpl createForTypeParameter(
|
||||
@NotNull TypeParameterDescriptor typeParameterDescriptor,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isFinal,
|
||||
@NotNull String debugName,
|
||||
@NotNull List<? extends TypeParameterDescriptor> parameters,
|
||||
@NotNull Collection<JetType> supertypes
|
||||
) {
|
||||
return new TypeConstructorImpl(typeParameterDescriptor, annotations, isFinal, debugName, parameters, supertypes) {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this == obj;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final List<TypeParameterDescriptor> parameters;
|
||||
private final Collection<JetType> supertypes;
|
||||
private final String debugName;
|
||||
private final boolean isFinal;
|
||||
|
||||
@Nullable
|
||||
private final ClassifierDescriptor classifierDescriptor;
|
||||
|
||||
public TypeConstructorImpl(
|
||||
private TypeConstructorImpl(
|
||||
@Nullable ClassifierDescriptor classifierDescriptor,
|
||||
@NotNull Annotations annotations,
|
||||
boolean isFinal,
|
||||
@@ -84,4 +130,10 @@ public class TypeConstructorImpl extends AnnotatedImpl implements TypeConstructo
|
||||
public ClassifierDescriptor getDeclarationDescriptor() {
|
||||
return classifierDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
|
||||
@Override
|
||||
public abstract boolean equals(Object obj);
|
||||
}
|
||||
|
||||
+2
-1
@@ -181,11 +181,12 @@ public class TypeCheckingProcedure {
|
||||
|
||||
List<TypeProjection> subArguments = subtype.getArguments();
|
||||
List<TypeProjection> superArguments = supertype.getArguments();
|
||||
if (subArguments.size() != superArguments.size()) return false;
|
||||
|
||||
List<TypeParameterDescriptor> parameters = constructor.getParameters();
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
TypeParameterDescriptor parameter = parameters.get(i);
|
||||
|
||||
|
||||
TypeProjection subArgument = subArguments.get(i);
|
||||
JetType subIn = getInType(parameter, subArgument);
|
||||
JetType subOut = getOutType(parameter, subArgument);
|
||||
|
||||
+2
-1
@@ -34,6 +34,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.AbstractClassTypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
@@ -329,7 +330,7 @@ public class DeserializedClassDescriptor extends AbstractClassDescriptor impleme
|
||||
return "deserialized class " + getName().toString();
|
||||
}
|
||||
|
||||
private class DeserializedClassTypeConstructor implements TypeConstructor {
|
||||
private class DeserializedClassTypeConstructor extends AbstractClassTypeConstructor {
|
||||
private final Collection<JetType> supertypes = computeSuperTypes();
|
||||
private final List<TypeParameterDescriptor> parameters;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user