data deprecations (empty constructors, non val/var arguments, vararg, superclasses) are now errors, relevant tests fixed

This commit is contained in:
Mikhail Glukhikh
2015-10-16 17:10:39 +03:00
parent cae0388a57
commit a4af6a3076
32 changed files with 41 additions and 156 deletions
@@ -185,7 +185,7 @@ public interface Errors {
DiagnosticFactory0<JetTypeReference> FINAL_SUPERTYPE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetTypeReference> DATA_CLASS_CANNOT_HAVE_CLASS_SUPERTYPES = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetTypeReference> DATA_CLASS_CANNOT_HAVE_CLASS_SUPERTYPES = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetTypeReference> SINGLETON_IN_SUPERTYPE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetNullableType> NULLABLE_SUPERTYPE = DiagnosticFactory0.create(ERROR, NULLABLE_TYPE);
DiagnosticFactory0<JetTypeReference> DYNAMIC_SUPERTYPE = DiagnosticFactory0.create(ERROR);
@@ -411,9 +411,9 @@ public interface Errors {
DiagnosticFactory0<JetReferenceExpression> NAME_FOR_AMBIGUOUS_PARAMETER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> DATA_CLASS_WITHOUT_PARAMETERS = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetParameter> DATA_CLASS_VARARG_PARAMETER = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<JetParameter> DATA_CLASS_NOT_PROPERTY_PARAMETER = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<PsiElement> DATA_CLASS_WITHOUT_PARAMETERS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetParameter> DATA_CLASS_VARARG_PARAMETER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetParameter> DATA_CLASS_NOT_PROPERTY_PARAMETER = DiagnosticFactory0.create(ERROR);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -437,7 +437,7 @@ public class DefaultErrorMessages {
MAP.put(INTERFACE_WITH_SUPERCLASS, "An interface cannot inherit from a class");
MAP.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice");
MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from");
MAP.put(DATA_CLASS_CANNOT_HAVE_CLASS_SUPERTYPES, "Data class inheritance from other classes is deprecated");
MAP.put(DATA_CLASS_CANNOT_HAVE_CLASS_SUPERTYPES, "Data class inheritance from other classes is forbidden");
MAP.put(SEALED_SUPERTYPE, "This type is sealed, so it can be inherited by only its own nested classes or objects");
MAP.put(SEALED_SUPERTYPE_IN_LOCAL_CLASS, "Local class cannot extend a sealed class");
MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton");
@@ -659,9 +659,9 @@ public class DefaultErrorMessages {
MAP.put(NAME_FOR_AMBIGUOUS_PARAMETER, "Named argument is not allowed for a parameter with an ambiguous name");
MAP.put(DATA_CLASS_WITHOUT_PARAMETERS, "Data class without primary constructor parameters are deprecated");
MAP.put(DATA_CLASS_VARARG_PARAMETER, "Primary constructor vararg parameters are deprecated for data classes");
MAP.put(DATA_CLASS_NOT_PROPERTY_PARAMETER, "Primary constructor parameters without val / var are deprecated for data classes");
MAP.put(DATA_CLASS_WITHOUT_PARAMETERS, "Data class must have at least one primary constructor parameter");
MAP.put(DATA_CLASS_VARARG_PARAMETER, "Primary constructor vararg parameters are forbidden for data classes");
MAP.put(DATA_CLASS_NOT_PROPERTY_PARAMETER, "Data class primary constructor must have only property (val / var) parameters");
MAP.put(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED, "Right-hand side has anonymous type. Please specify type explicitly", TO_STRING);
-20
View File
@@ -1,20 +0,0 @@
interface Id<T> {
val id: T
}
data class Actor (
id: Int,
val firstName: String,
val lastName: String
) : Id<Int> {
override val id: Int = id
}
fun box(): String {
val a1 = Actor(1, "Jeff", "Bridges")
val a1copy = a1.copy(id = a1.id)
if (a1copy.id != a1.id) return "Failed: a1copy.id==${a1copy.id}"
return "OK"
}
@@ -12,7 +12,7 @@ internal data class A1(val prop1: String) {
fun f(): String = "$prop1#$prop2#$prop3"
}
internal data class A2 private constructor() {
internal class A2 private constructor() {
var prop1: String = ""
var prop2: String = "const2"
var prop3: String = ""
@@ -1,17 +0,0 @@
data class A(a: Int, b: String) {}
fun box() : String {
for (method in javaClass<A>().getDeclaredMethods()) {
if (method.getName() == "copy"){
val parameterTypes = method.getParameterTypes()
if (parameterTypes != null && parameterTypes.size() == 2) {
val copy = A(1, "a").copy(a = 2, b = "b")
return "OK"
}
else {
return "Method copy has " + (if (parameterTypes == null) "0" else parameterTypes.size()) + " parameters, expected 2"
}
}
}
return "fail"
}
@@ -1,4 +1,4 @@
data class A()
data class A(val arg: Any? = null)
fun box() : String {
val a = A()
@@ -1,13 +1,13 @@
data class A(val a: Any?, var x: Int)
data class B(val a: Any?, x: Int)
data class B(val a: Any?)
data class C(val a: Int, var x: Int?)
data class D(val a: Int?)
fun box() : String {
if( A(null,19).hashCode() != 19) "fail"
if( A(239,19).hashCode() != (239*31+19)) "fail"
if( B(null,19).hashCode() != 0) "fail"
if( B(239,19).hashCode() != 239) "fail"
if( B(null).hashCode() != 0) "fail"
if( B(239).hashCode() != 239) "fail"
if( C(239,19).hashCode() != (239*31+19)) "fail"
if( C(239,null).hashCode() != 239*31) "fail"
if( D(239).hashCode() != (239)) "fail"
@@ -1,7 +1,7 @@
data class A(var x: Int, y: Int, val z: Int)
data class A(var x: Int, val z: Int)
fun box(): String {
val a = A(1, 2, 3)
val a = A(1, 3)
if (a.component1() != 1) return "Fail: ${a.component1()}"
if (a.component2() != 3) return "Fail: ${a.component2()}"
return "OK"
@@ -1,10 +0,0 @@
abstract class SuperTrait {
override fun toString(): String = "!"
}
data class A(val x: Int): SuperTrait() {
}
fun box(): String {
return if (A(0).toString() == "!") "OK" else "fail"
}
@@ -1,7 +1,7 @@
data class A(var x: Int, y: Int, val z: Int?)
data class A(var x: Int, val z: Int?)
fun box(): String {
val a = A(1, 2, null)
val a = A(1, null)
if("$a" != "A(x=1, z=null)") return "$a"
return "OK"
}
@@ -1,3 +1,3 @@
package test
data class DataClass(var x: String, y: Int, val z: Double)
data class DataClass(var x: String, val z: Double)
@@ -1,7 +1,7 @@
package test
@kotlin.data() public final class DataClass {
/*primary*/ public constructor DataClass(/*0*/ x: kotlin.String, /*1*/ y: kotlin.Int, /*2*/ z: kotlin.Double)
/*primary*/ public constructor DataClass(/*0*/ x: kotlin.String, /*1*/ z: kotlin.Double)
public final var x: kotlin.String
public final fun <get-x>(): kotlin.String
public final fun <set-x>(/*0*/ <set-?>: kotlin.String): kotlin.Unit
@@ -9,5 +9,5 @@ package test
public final fun <get-z>(): kotlin.Double
public final operator /*synthesized*/ fun component1(): kotlin.String
public final operator /*synthesized*/ fun component2(): kotlin.Double
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.String = ..., /*1*/ y: kotlin.Int, /*2*/ z: kotlin.Double = ...): test.DataClass
public final /*synthesized*/ fun copy(/*0*/ x: kotlin.String = ..., /*1*/ z: kotlin.Double = ...): test.DataClass
}
@@ -1,4 +0,0 @@
package test
data class DataClass
data class OtherDataClass()
@@ -1,7 +0,0 @@
//ALLOW_AST_ACCESS
package test
data class A(foo: String, val bar: Int, other: Long) {
val foo = foo
val other = other
}
@@ -1516,12 +1516,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt6136_2.kt")
public void testKt6136_2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/kt6136_2.kt");
doTest(fileName);
}
@TestMetadata("kt6816.kt")
public void testKt6816() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/kt6816.kt");
@@ -1212,12 +1212,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("paramWithoutProperty.kt")
public void testParamWithoutProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/dataClasses/copy/paramWithoutProperty.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("valInConstructorParams.kt")
public void testValInConstructorParams() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/dataClasses/copy/valInConstructorParams.kt");
@@ -1389,12 +1383,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("alreadyInherited.kt")
public void testAlreadyInherited() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/dataClasses/tostring/alreadyInherited.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("arrayParams.kt")
public void testArrayParams() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/dataClasses/tostring/arrayParams.kt");
@@ -2944,24 +2944,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledKotlin(fileName);
}
@TestMetadata("NoComponents.kt")
public void testNoComponents() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/NoComponents.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("OneVal.kt")
public void testOneVal() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/OneVal.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("ParamNameSameToField.kt")
public void testParamNameSameToField() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("TwoVals.kt")
public void testTwoVals() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/TwoVals.kt");
@@ -1033,24 +1033,12 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith
doTest(fileName);
}
@TestMetadata("NoComponents.kt")
public void testNoComponents() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/NoComponents.kt");
doTest(fileName);
}
@TestMetadata("OneVal.kt")
public void testOneVal() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/OneVal.kt");
doTest(fileName);
}
@TestMetadata("ParamNameSameToField.kt")
public void testParamNameSameToField() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt");
doTest(fileName);
}
@TestMetadata("TwoVals.kt")
public void testTwoVals() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/TwoVals.kt");
@@ -1035,24 +1035,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
doTest(fileName);
}
@TestMetadata("NoComponents.kt")
public void testNoComponents() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/NoComponents.kt");
doTest(fileName);
}
@TestMetadata("OneVal.kt")
public void testOneVal() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/OneVal.kt");
doTest(fileName);
}
@TestMetadata("ParamNameSameToField.kt")
public void testParamNameSameToField() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt");
doTest(fileName);
}
@TestMetadata("TwoVals.kt")
public void testTwoVals() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/TwoVals.kt");