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");
@@ -3,7 +3,7 @@
package test
@dependency.A @dependency.B @dependency.C @kotlin.data public final class Annotations public constructor() {
@dependency.A @dependency.B @dependency.C public final class Annotations public constructor() {
@dependency.A @dependency.B @dependency.C @kotlin.inline public final val p: @dependency.B kotlin.Int /* compiled code */
@dependency.A @dependency.B @dependency.C @kotlin.inline public final fun f(@dependency.A @dependency.B @dependency.C i: @dependency.A kotlin.Int): kotlin.Unit { /* compiled code */ }
@@ -2,7 +2,7 @@ package test
import dependency.*
data @A("a") @B(1) @C class Annotations {
@A("a") @B(1) @C class Annotations {
inline @A("f") @B(2) @C fun f(@A("i") @B(3) @C i: @A("int") Int) {
}
@@ -9,7 +9,7 @@ class A @Ann(1)private constructor(x: Int) {
inner class B() // do not insert here
inner class C protected constructor() {
fun foo() {
data class Local private constructor()
class Local private constructor()
}
}
}
@@ -9,7 +9,7 @@ class A @Ann(1)<caret>private (x: Int) {
inner class B() // do not insert here
inner class C protected () {
fun foo() {
data class Local private()
class Local private()
}
}
}
@@ -1033,24 +1033,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest {
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");
+2 -2
View File
@@ -1,6 +1,6 @@
package foo
data class Dat(val start: String, middle: String, val end: String) {
data class Dat(val start: String, val middle: String, val end: String) {
fun getLabel() : String {
return start + end
}
@@ -9,7 +9,7 @@ data class Dat(val start: String, middle: String, val end: String) {
fun box(): String {
val d = Dat("max", "-", "min")
assertEquals("maxmin", d.getLabel())
val (p1, p2) = d
val (p1, p, p2) = d
assertEquals("max", p1)
assertEquals("min", p2)
return "OK"
+2 -2
View File
@@ -1,11 +1,11 @@
package foo
data class Dat(val start: String, middle: String, val end: String)
data class Dat(val start: String, val middle: String, val end: String)
fun box(): String {
val d1 = Dat("OO", "-", "PS")
val d2: Dat = d1.copy(end = "K", middle = "+")
val d3: Dat = d2.copy(start = "O", middle = "-")
val (p1, p2) = d3
val (p1, p, p2) = d3
return p1 + p2
}
+1 -1
View File
@@ -2,7 +2,7 @@ package foo
var t: Any? = null
data class Dat(val start: String, middle: String, val end: String) {
data class Dat(val start: String, val middle: String, val end: String) {
override fun toString() = "another string"
override fun hashCode() = 371
override fun equals(other: Any?): Boolean {
@@ -3,7 +3,7 @@ package foo
import java.util.*
data class A
class A
fun checkAbstractList(obj: Any) {
assertTrue(obj is AbstractList<*>, "checkAbstractList: is AbstractList")
@@ -1,6 +1,6 @@
package org.test
public data class SomeClass {
public data class SomeClass(val arg: Any? = null) {
public val immutableProperty: Int = 5
@java.lang.Deprecated get
@@ -8,4 +8,9 @@ f 2 0/SomeClass mutableProperty
m 1 0/SomeClass getMutableProperty
m 2 0/SomeClass getMutableProperty
m 1 0/SomeClass setMutableProperty
a org.jetbrains.annotations.Nullable 3
f 3 0/SomeClass arg
m 3 0/SomeClass getArg
m 3 0/SomeClass component1
m 2 0/SomeClass copy
m 2 0/SomeClass copy$default
@@ -8,5 +8,9 @@ m 2 SomeClass getAnnotatedProperty
m 1 SomeClass annotatedFunction
a kotlin.inline 3
m 3 SomeClass annotatedFunction
f 2 SomeClass arg
m 2 SomeClass getArg
m 2 SomeClass component1
a org.jetbrains.annotations.NotNull 4
m 4 SomeClass copy
m 4 SomeClass copy$default
@@ -1,4 +1,4 @@
data public class SomeClass {
data public class SomeClass(val arg: Any? = null) {
@java.lang.Deprecated public var annotatedProperty: String? = null