Defining flexible type semantic equality through subtyping

This commit is contained in:
Andrey Breslav
2014-10-14 08:07:55 +04:00
parent f41a8d2c00
commit 3453809b4b
6 changed files with 41 additions and 4 deletions
@@ -0,0 +1,24 @@
// FILE: p/J.java
package p;
public class J<T> {
public void foo(Ref<T[]> r) {}
}
// FILE: p/Ref.java
package p;
public class Ref<T> {
public static <T> Ref<T> create() { return null; }
}
// FILE: k.kt
import p.*
fun main(j: J<String>) {
val r = Ref.create<Array<String>>()
j.foo(r)
}
@@ -0,0 +1,3 @@
package
internal fun main(/*0*/ j: p.J<kotlin.String>): kotlin.Unit
@@ -3,8 +3,7 @@ package test
public trait ErrorTypes {
public trait Sub : test.ErrorTypes.Super {
public abstract fun errorTypeInParameter(/*0*/ list: kotlin.(Mutable)List<kotlin.Array<(out) [ERROR : Unresolved java classifier: T]!>!>!): kotlin.Unit
public abstract override /*1*/ /*fake_override*/ fun errorTypeInParameter(/*0*/ list: kotlin.(Mutable)List<kotlin.Array<(out) [ERROR : Unresolved java classifier: T]!>!>!): kotlin.Unit
public abstract override /*1*/ fun errorTypeInParameter(/*0*/ list: kotlin.(Mutable)List<kotlin.Array<(out) [ERROR : Unresolved java classifier: T]!>!>!): kotlin.Unit
public abstract override /*1*/ fun returnErrorType(): [ERROR : Unresolved java classifier: T]!
}
@@ -7845,6 +7845,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("genericsAndArrays.kt")
public void testGenericsAndArrays() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/genericsAndArrays.kt");
doTest(fileName);
}
@TestMetadata("int.kt")
public void testInt() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/methodCall/int.kt");
@@ -71,8 +71,7 @@ public class TypeCheckingProcedure {
public boolean equalTypes(@NotNull JetType type1, @NotNull JetType type2) {
if (TypesPackage.isFlexible(type1)) {
if (TypesPackage.isFlexible(type2)) {
return equalTypes(TypesPackage.flexibility(type1).getLowerBound(), TypesPackage.flexibility(type2).getLowerBound())
&& equalTypes(TypesPackage.flexibility(type1).getUpperBound(), TypesPackage.flexibility(type2).getUpperBound());
return !type1.isError() && !type2.isError() && isSubtypeOf(type1, type2) && isSubtypeOf(type2, type1);
}
return heterogeneousEquivalence(type2, type1);
}
+6
View File
@@ -34,6 +34,12 @@ Least Upper Bound (aka "common supertype"):
* `lub[(A..B), (C..D)] = (lub[A, C], lub[B, D])
Type equivalence (aka `JetTypeChecker.DEFAULT.equalTypes()`):
`T1 ~~ T2 <=> T1 <: T2 && T2 <: T1`
NOTE: This relation is NOT transitive: `T?` ~~ (T..T?)` and `(T..T?) ~~ T`, but `T? !~ T`
## Loading Java Types