Fixed problem with overriding method with non-trivial raw type (when erased type parameter has upper bound)
Also added cases for the code which was changed.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
//FILE: Foo.java
|
||||
public class Foo<T extends CharSequence> {
|
||||
}
|
||||
|
||||
//FILE: Bar.java
|
||||
public interface Bar {
|
||||
void f(Foo f);
|
||||
}
|
||||
|
||||
//FILE: a.kt
|
||||
class BarImpl: Bar {
|
||||
override fun f(f: Foo<out CharSequence?>?) {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package test;
|
||||
|
||||
public interface RawTypeWithUpperBound {
|
||||
|
||||
public interface Foo<T extends CharSequence> {
|
||||
}
|
||||
|
||||
interface Bar {
|
||||
void f(Foo f);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package test
|
||||
|
||||
public trait RawTypeWithUpperBound : java.lang.Object {
|
||||
|
||||
public trait Bar : java.lang.Object {
|
||||
public abstract fun f(/*0*/ p0: test.RawTypeWithUpperBound.Foo<out jet.CharSequence?>?): jet.Unit
|
||||
}
|
||||
|
||||
public trait Foo</*0*/ T : jet.CharSequence?> : java.lang.Object {
|
||||
}
|
||||
}
|
||||
|
||||
package test.RawTypeWithUpperBound {
|
||||
public /*synthesized*/ fun Bar(/*0*/ function: (test.RawTypeWithUpperBound.Foo<out jet.CharSequence?>?) -> jet.Unit): test.RawTypeWithUpperBound.Bar
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test;
|
||||
|
||||
public interface RawUpperBound<T extends RawUpperBound> {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
public trait RawUpperBound</*0*/ T : test.RawUpperBound<out jet.Any?>?> : java.lang.Object {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test;
|
||||
|
||||
public interface RecursiveRawUpperBound<T extends RecursiveRawUpperBound> {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
public trait RecursiveRawUpperBound</*0*/ T : test.RecursiveRawUpperBound<out jet.Any?>?> : java.lang.Object {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test;
|
||||
|
||||
public interface RecursiveWildcardUpperBound<T extends RecursiveWildcardUpperBound> {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package test
|
||||
|
||||
public trait RecursiveWildcardUpperBound</*0*/ T : test.RecursiveWildcardUpperBound<out jet.Any?>?> : java.lang.Object {
|
||||
}
|
||||
@@ -4558,6 +4558,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest("compiler/testData/diagnostics/tests/j+k/mutableIterator.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overrideRawType.kt")
|
||||
public void testOverrideRawType() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/j+k/overrideRawType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("OverrideVararg.kt")
|
||||
public void testOverrideVararg() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt");
|
||||
|
||||
@@ -59,6 +59,26 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/PackageLocalVisibility.java");
|
||||
}
|
||||
|
||||
@TestMetadata("RawTypeWithUpperBound.java")
|
||||
public void testRawTypeWithUpperBound() throws Exception {
|
||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/RawTypeWithUpperBound.java");
|
||||
}
|
||||
|
||||
@TestMetadata("RawUpperBound.java")
|
||||
public void testRawUpperBound() throws Exception {
|
||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/RawUpperBound.java");
|
||||
}
|
||||
|
||||
@TestMetadata("RecursiveRawUpperBound.java")
|
||||
public void testRecursiveRawUpperBound() throws Exception {
|
||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/RecursiveRawUpperBound.java");
|
||||
}
|
||||
|
||||
@TestMetadata("RecursiveWildcardUpperBound.java")
|
||||
public void testRecursiveWildcardUpperBound() throws Exception {
|
||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/RecursiveWildcardUpperBound.java");
|
||||
}
|
||||
|
||||
@TestMetadata("SubclassFromNested.java")
|
||||
public void testSubclassFromNested() throws Exception {
|
||||
doTestCompiledJava("compiler/testData/loadJava/compiledJava/SubclassFromNested.java");
|
||||
|
||||
+20
-16
@@ -79,9 +79,12 @@ class LazyJavaTypeResolver(
|
||||
|
||||
private class LazyStarProjection(
|
||||
c: LazyJavaResolverContext,
|
||||
val typeParameter: TypeParameterDescriptor
|
||||
val typeParameter: TypeParameterDescriptor,
|
||||
val attr: JavaTypeAttributes
|
||||
) : TypeProjectionBase() {
|
||||
override fun getProjectionKind() = if (typeParameter.getVariance() == OUT_VARIANCE) INVARIANT else OUT_VARIANCE
|
||||
override fun getProjectionKind() =
|
||||
// projections are not allowed in immediate arguments of supertypes
|
||||
if (typeParameter.getVariance() == OUT_VARIANCE || attr.howThisTypeIsUsed == SUPERTYPE) INVARIANT else OUT_VARIANCE
|
||||
override fun getType() = typeParameter.getUpperBoundsAsType()
|
||||
}
|
||||
|
||||
@@ -167,18 +170,19 @@ class LazyJavaTypeResolver(
|
||||
if (isRaw()) {
|
||||
return typeParameters.map {
|
||||
parameter ->
|
||||
// not making a star projection because of this case:
|
||||
// Java:
|
||||
// class C<T extends C> {}
|
||||
// The upper bound is raw here, and we can't compute the projection: it would be infinite:
|
||||
// C<*> = C<out C<out C<...>>>
|
||||
// this way we loose some type information, even when the case is not so bad, but it doesn't seem to matter
|
||||
|
||||
// projections are not allowed in immediate arguments of supertypes
|
||||
val projectionKind = if (parameter.getVariance() == OUT_VARIANCE || attr.howThisTypeIsUsed == SUPERTYPE)
|
||||
INVARIANT
|
||||
else OUT_VARIANCE
|
||||
TypeProjectionImpl(projectionKind, KotlinBuiltIns.getInstance().getNullableAnyType())
|
||||
if (attr.howThisTypeIsUsed == UPPER_BOUND) {
|
||||
// not making a star projection because of this case:
|
||||
// Java:
|
||||
// class C<T extends C> {}
|
||||
// The upper bound is raw here, and we can't compute the projection: it would be infinite:
|
||||
// C<*> = C<out C<out C<...>>>
|
||||
// this way we lose some type information, even when the case is not so bad, but it doesn't seem to matter
|
||||
val projectionKind = if (parameter.getVariance() == OUT_VARIANCE) INVARIANT else OUT_VARIANCE
|
||||
TypeProjectionImpl(projectionKind, KotlinBuiltIns.getInstance().getNullableAnyType())
|
||||
}
|
||||
else
|
||||
LazyStarProjection(c, parameter, attr)
|
||||
}
|
||||
}
|
||||
if (isConstructorTypeParameter()) {
|
||||
@@ -209,7 +213,7 @@ class LazyJavaTypeResolver(
|
||||
is JavaWildcardType -> {
|
||||
val bound = javaType.getBound()
|
||||
if (bound == null)
|
||||
LazyStarProjection(c, typeParameter)
|
||||
LazyStarProjection(c, typeParameter, attr)
|
||||
else {
|
||||
var projectionKind = if (javaType.isExtends()) OUT_VARIANCE else IN_VARIANCE
|
||||
if (projectionKind == typeParameter.getVariance()) {
|
||||
@@ -263,11 +267,11 @@ class LazyJavaTypeAttributes(
|
||||
c: LazyJavaResolverContext,
|
||||
val annotationOwner: JavaAnnotationOwner,
|
||||
override val howThisTypeIsUsed: TypeUsage,
|
||||
computeHowThisTypeIsUsedAccrodingToAnnotations: () -> TypeUsage = {howThisTypeIsUsed}
|
||||
computeHowThisTypeIsUsedAccordingToAnnotations: () -> TypeUsage = {howThisTypeIsUsed}
|
||||
): JavaTypeAttributes {
|
||||
|
||||
override val howThisTypeIsUsedAccordingToAnnotations: TypeUsage by c.storageManager.createLazyValue(
|
||||
computeHowThisTypeIsUsedAccrodingToAnnotations
|
||||
computeHowThisTypeIsUsedAccordingToAnnotations
|
||||
)
|
||||
|
||||
override val isMarkedNotNull: Boolean by c.storageManager.createLazyValue { c.hasNotNullAnnotation(annotationOwner) }
|
||||
|
||||
Reference in New Issue
Block a user