Specificity supported for dynamic types

This commit is contained in:
Andrey Breslav
2014-11-09 14:05:58 +02:00
parent 20513abe04
commit 65794183e7
7 changed files with 75 additions and 4 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypesPackage;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import java.util.List;
@@ -70,8 +71,8 @@ public class OverloadUtil {
for (int i = 0; i < superValueParameters.size(); ++i) {
JetType superValueParameterType = OverridingUtil.getUpperBound(superValueParameters.get(i));
JetType subValueParameterType = OverridingUtil.getUpperBound(subValueParameters.get(i));
// TODO: compare erasure
if (!JetTypeChecker.DEFAULT.equalTypes(superValueParameterType, subValueParameterType)) {
if (!JetTypeChecker.DEFAULT.equalTypes(superValueParameterType, subValueParameterType)
|| TypesPackage.oneMoreSpecificThanAnother(subValueParameterType, superValueParameterType)) {
return OverridingUtil.OverrideCompatibilityInfo
.valueParameterTypeMismatch(superValueParameterType, subValueParameterType, INCOMPATIBLE);
}
@@ -0,0 +1,26 @@
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER
// MODULE[js]: m1
// FILE: k.kt
fun dyn(d: dynamic) {}
fun foo(d: dynamic): String = ""
fun foo(d: Int): Int = 1
fun nothing(d: dynamic): Int = 1
fun nothing(d: Nothing): String = ""
fun test(d: dynamic) {
dyn(1)
dyn("")
foo(1).checkType { it : _<Int> }
foo("").checkType { it : _<String> }
// Checking specificity of `dynamic` vs `Nothing`
nothing(d).checkType { it : _<String> }
nothing("").checkType { it : _<Int> }
[suppress("UNREACHABLE_CODE")] nothing(null!!).checkType { it : _<String> }
}
@@ -0,0 +1,8 @@
package
internal fun dyn(/*0*/ d: (kotlin.Nothing..kotlin.Any?)): kotlin.Unit
internal fun foo(/*0*/ d: (kotlin.Nothing..kotlin.Any?)): kotlin.String
internal fun foo(/*0*/ d: kotlin.Int): kotlin.Int
internal fun nothing(/*0*/ d: dynamic): kotlin.Int
internal fun nothing(/*0*/ d: kotlin.Nothing): kotlin.String
internal fun test(/*0*/ d: dynamic): kotlin.Unit
@@ -3722,6 +3722,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("overloading.kt")
public void testOverloading() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dynamicTypes/overloading.kt");
doTest(fileName);
}
@TestMetadata("unsupported.kt")
public void testUnsupported() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dynamicTypes/unsupported.kt");