Account for substitutions of one variable for another (it must remain a variable)

This commit is contained in:
Andrey Breslav
2014-08-25 20:03:25 +04:00
parent bdbd469aad
commit 969beb7898
3 changed files with 46 additions and 15 deletions
@@ -0,0 +1,23 @@
// FILE: p/Visitor.java
package p;
public interface Visitor<D> {
}
// FILE: p/Element.java
package p;
public class Element {
public <D> R accept(@NotNull Visitor<D> visitor, D data) {return null;}
}
// FILE: k.kt
import p.*
fun test(v: Visitor<Nothing>, e: Element) {
e.accept(v, null)
}
@@ -7811,6 +7811,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName); doTest(fileName);
} }
@TestMetadata("visitor.kt")
public void testVisitor() throws Exception {
doTest("compiler/testData/diagnostics/tests/platformTypes/methodCall/visitor.kt");
}
} }
} }
@@ -264,18 +264,10 @@ class LazyJavaTypeResolver(
override fun isNullable(): Boolean = _nullable() override fun isNullable(): Boolean = _nullable()
} }
/* private open class FlexibleJavaClassifierType(
* For a java type like java.util.List<Foo> lowerBound: JetType,
* lowerBound = MutableList<Foo> upperBound: JetType
* upperBound = List<Foo?> ) : DelegatingFlexibleType(lowerBound, upperBound), CustomTypeVariable {
*/
private inner class LazyFlexibleJavaClassifierType(
javaType: JavaClassifierType,
attr: JavaTypeAttributes
) : DelegatingFlexibleType(
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_LOWER_BOUND)),
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_UPPER_BOUND))
), CustomTypeVariable {
override val isTypeVariable: Boolean = lowerBound.getConstructor() == upperBound.getConstructor() override val isTypeVariable: Boolean = lowerBound.getConstructor() == upperBound.getConstructor()
&& lowerBound.getConstructor().getDeclarationDescriptor() is TypeParameterDescriptor && lowerBound.getConstructor().getDeclarationDescriptor() is TypeParameterDescriptor
@@ -284,11 +276,22 @@ class LazyJavaTypeResolver(
override fun substitutionResult(replacement: JetType): JetType { override fun substitutionResult(replacement: JetType): JetType {
return if (replacement.isFlexible()) replacement return if (replacement.isFlexible()) replacement
else DelegatingFlexibleType(TypeUtils.makeNotNullable(replacement), TypeUtils.makeNullable(replacement)) else FlexibleJavaClassifierType(TypeUtils.makeNotNullable(replacement), TypeUtils.makeNullable(replacement))
} }
} }
private class JavaTypeVariable() /*
* For a java type like java.util.List<Foo>
* lowerBound = MutableList<Foo>
* upperBound = List<Foo?>
*/
private inner class LazyFlexibleJavaClassifierType(
javaType: JavaClassifierType,
attr: JavaTypeAttributes
) : FlexibleJavaClassifierType(
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_LOWER_BOUND)),
LazyJavaClassifierType(javaType, attr.toFlexible(FLEXIBLE_UPPER_BOUND))
)
} }
trait JavaTypeAttributes { trait JavaTypeAttributes {