diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 213871f03a6..ba27a05c22d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -159,6 +159,7 @@ public interface Errors { DiagnosticFactory0 SECONDARY_CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED = DiagnosticFactory0.create(WARNING); // Trait-specific diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 8c8a12fc30d..c15cbd4f63a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -418,6 +418,8 @@ public class DefaultErrorMessages { MAP.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor"); MAP.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected"); + MAP.put(INIT_KEYWORD_BEFORE_CLASS_INITIALIZER_EXPECTED, "Expecting 'init' keyword before class initializer"); + MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING); MAP.put(NO_TAIL_CALLS_FOUND, "A function is marked as tail-recursive but no tail calls are found"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java index 38e170f85ee..82c219a795a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassInitializer.java @@ -20,6 +20,7 @@ import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.lexer.JetTokens; import org.jetbrains.kotlin.psi.stubs.KotlinPlaceHolderStub; import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes; @@ -49,4 +50,14 @@ public class JetClassInitializer extends JetDeclarationStub? = null class MyClass() { - { + init { accessedFromConstructor = javaClass() } } diff --git a/compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.kt b/compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.kt index a84fbeee48f..65e6d55d878 100644 --- a/compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.kt +++ b/compiler/testData/diagnostics/tests/AnonymousInitializerVarAndConstructor.kt @@ -3,7 +3,7 @@ class A(w: Int) { var c = w - { + init { c = 81 } } diff --git a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt index 86c15a5c185..69df0631f6b 100644 --- a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt +++ b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt @@ -1,18 +1,18 @@ trait NoC { - { + init { } val a : Int get() = 1 - { + init { } } class WithC() { val x : Int - { + init { $x = 1 $y = 2 val b = x @@ -21,7 +21,7 @@ class WithC() { val a : Int get() = 1 - { + init { val z = b val zz = x val zzz = $a diff --git a/compiler/testData/diagnostics/tests/Dollar.kt b/compiler/testData/diagnostics/tests/Dollar.kt index 1adf1bd99ea..96173ecf238 100644 --- a/compiler/testData/diagnostics/tests/Dollar.kt +++ b/compiler/testData/diagnostics/tests/Dollar.kt @@ -6,7 +6,7 @@ open class `$`() { } open class `$$`(`$$$$` : `$$$$$`?) : `$`() { val `$$$` : `$$$$$`? - { + init { $`$$$` = `$$$$` } open public fun `$$$$$$`() : `$$$$$`? { diff --git a/compiler/testData/diagnostics/tests/Properties.kt b/compiler/testData/diagnostics/tests/Properties.kt index 332142bc57c..61a7a254946 100644 --- a/compiler/testData/diagnostics/tests/Properties.kt +++ b/compiler/testData/diagnostics/tests/Properties.kt @@ -16,7 +16,7 @@ class Test() { var a : Int = 111 var b : Int get() = $a; set(x) {a = x; $a = x} - { + init { $b = $a $a = $b a = $b diff --git a/compiler/testData/diagnostics/tests/UnusedParameters.kt b/compiler/testData/diagnostics/tests/UnusedParameters.kt index 1aaf76ae0c7..a160285e259 100644 --- a/compiler/testData/diagnostics/tests/UnusedParameters.kt +++ b/compiler/testData/diagnostics/tests/UnusedParameters.kt @@ -1,11 +1,11 @@ class C(a: Int, b: Int, c: Int, d: Int, e: Int = d, val f: String) { - { + init { a + a } val g = b - { + init { c + c } } diff --git a/compiler/testData/diagnostics/tests/UnusedVariables.kt b/compiler/testData/diagnostics/tests/UnusedVariables.kt index 9e2ef9afe07..7a52bf525b6 100644 --- a/compiler/testData/diagnostics/tests/UnusedVariables.kt +++ b/compiler/testData/diagnostics/tests/UnusedVariables.kt @@ -38,7 +38,7 @@ class MyTest() { $a = v } - { + init { a = "rr" } @@ -133,7 +133,7 @@ fun testObject() : Trait { fun testBackingFieldsNotMarked() { val a = object { val x : Int - { + init { $x = 1 } } diff --git a/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt index 26654ab8a7a..f6b695ba50c 100644 --- a/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt +++ b/compiler/testData/diagnostics/tests/annotations/kt1886annotationBody.kt @@ -15,7 +15,7 @@ annotation class Annotation5() { } annotation class Annotation6() { - {} + init {} } annotation class Annotation1() {} diff --git a/compiler/testData/diagnostics/tests/annotations/onInitializer.kt b/compiler/testData/diagnostics/tests/annotations/onInitializer.kt index 919c87fdf14..80e3b065fda 100644 --- a/compiler/testData/diagnostics/tests/annotations/onInitializer.kt +++ b/compiler/testData/diagnostics/tests/annotations/onInitializer.kt @@ -1,15 +1,15 @@ class A { - ann {} - [ann] {} - aaa {} - [aaa] {} + ann init {} + [ann] init {} + aaa init {} + [aaa] init {} } trait T { - ann {} - [ann] {} - aaa {} - [aaa] {} + ann init {} + [ann] init {} + aaa init {} + [aaa] init {} } annotation class ann \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt b/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt index df569d9c53e..135edcfee1f 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadForwardInAnonymous.kt @@ -1,5 +1,5 @@ class ReadForward() { - { + init { val x = $a } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt b/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt index 4f76161cb6e..751c6130e43 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadInAnonymous.kt @@ -1,6 +1,6 @@ class ReadByAnotherPropertyInitializer() { val a = 1 - { + init { val x = $a } } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadNonexistentAbstractPropertyInAnonymous.kt b/compiler/testData/diagnostics/tests/backingField/ReadNonexistentAbstractPropertyInAnonymous.kt index e9a554270b1..d826a3e73f0 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadNonexistentAbstractPropertyInAnonymous.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadNonexistentAbstractPropertyInAnonymous.kt @@ -1,7 +1,7 @@ abstract class ReadNonexistent() { abstract val aa: Int - { + init { val x = $aa } } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadNonexistentCustomGetInAnonymous.kt b/compiler/testData/diagnostics/tests/backingField/ReadNonexistentCustomGetInAnonymous.kt index 0e9aaa34d55..7dfb6133b9c 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadNonexistentCustomGetInAnonymous.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadNonexistentCustomGetInAnonymous.kt @@ -2,7 +2,7 @@ class ReadNonexistent() { val a: Int get() = 1 - { + init { val x = $a } } diff --git a/compiler/testData/diagnostics/tests/backingField/ReadNonexistentPropertyInAnonymous.kt b/compiler/testData/diagnostics/tests/backingField/ReadNonexistentPropertyInAnonymous.kt index 8ad001b5e8f..5b5a89f2a25 100644 --- a/compiler/testData/diagnostics/tests/backingField/ReadNonexistentPropertyInAnonymous.kt +++ b/compiler/testData/diagnostics/tests/backingField/ReadNonexistentPropertyInAnonymous.kt @@ -1,5 +1,5 @@ class Cl() { - { + init { val x = $a } } diff --git a/compiler/testData/diagnostics/tests/backingField/WriteNonexistentDeclaredInHigher.kt b/compiler/testData/diagnostics/tests/backingField/WriteNonexistentDeclaredInHigher.kt index 2a971f7aec1..d35b0a3d4ae 100644 --- a/compiler/testData/diagnostics/tests/backingField/WriteNonexistentDeclaredInHigher.kt +++ b/compiler/testData/diagnostics/tests/backingField/WriteNonexistentDeclaredInHigher.kt @@ -1,7 +1,7 @@ val y = 1 class A() { - { + init { $y = 1 } } diff --git a/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt b/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt index b11943036ca..817abdec5e1 100644 --- a/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt +++ b/compiler/testData/diagnostics/tests/backingField/kt462BackingFieldsResolve.kt @@ -5,23 +5,23 @@ package kt462 abstract class TestInitializationWithoutBackingField() { val valWithBackingField : Int - { + init { valWithBackingField = 2 } val valWithoutBackingField : Int get() = 42 - { + init { valWithoutBackingField = 45 } var finalDefaultVar : Int - { + init { finalDefaultVar = 3 } open var openVar : Int - { + init { openVar = 4 } @@ -29,42 +29,42 @@ abstract class TestInitializationWithoutBackingField() { set(v: Int) { $varWithCustomSetter = v } - { + init { varWithCustomSetter = 3 } var varWithoutBackingField : Int get() = 3 set(v: Int) {} - { + init { varWithoutBackingField = 4 } abstract var abstractVar : Int - { + init { abstractVar = 34 } } abstract class TestInitializationThroughBackingField() { val valWithBackingField : Int - { + init { $valWithBackingField = 2 } val valWithoutBackingField : Int get() = 42 - { + init { $valWithoutBackingField = 45 } var finalDefaultVar : Int - { + init { $finalDefaultVar = 3 } open var openVar : Int - { + init { $openVar = 4 } @@ -72,26 +72,26 @@ abstract class TestInitializationThroughBackingField() { set(v: Int) { $varWithCustomSetter = v } - { + init { $varWithCustomSetter = 3 } var varWithoutBackingField : Int get() = 3 set(v: Int) {} - { + init { $varWithoutBackingField = 4 } abstract var abstractVar : Int - { + init { $abstractVar = 34 } } class TestBackingFieldsVisibility() { var a : Int = 712 - { + init { $a = 37 this.$a = 357 } @@ -122,7 +122,7 @@ val topLevelVar = 11 class T() { val z : Int get() = 42 - { + init { this.$z = 34 } @@ -132,7 +132,7 @@ class T() { val a = object { val x = $z - { + init { $z = 23 } } @@ -140,7 +140,7 @@ class T() { var x: Int = 2 get() { val o = object { - { + init { $x = 34 } fun foo() { @@ -164,7 +164,7 @@ class T() { $x = 34 val o = object { val y = $x - { + init { $x = 422 } } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt index a95c97a2127..165539c9541 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/UninitializedOrReassignedVariables.kt @@ -112,7 +112,7 @@ val y = 10 val z = 10 class AnonymousInitializers(var a: String, val b: String) { - { + init { $a = "30" a = "s" @@ -121,11 +121,11 @@ class AnonymousInitializers(var a: String, val b: String) { } val i: Int - { + init { $i = 121 } - { + init { x = 11 z = 10 } @@ -133,14 +133,14 @@ class AnonymousInitializers(var a: String, val b: String) { val j: Int get() = 20 - { + init { $i = 13 $j = 30 j = 34 } val k: String - { + init { if (1 < 3) { k = "a" } @@ -150,7 +150,7 @@ class AnonymousInitializers(var a: String, val b: String) { } val l: String - { + init { if (1 < 3) { $l = "a" } @@ -160,7 +160,7 @@ class AnonymousInitializers(var a: String, val b: String) { } val o: String - { + init { if (1 < 3) { $o = "a" } @@ -168,13 +168,13 @@ class AnonymousInitializers(var a: String, val b: String) { var m: Int = 30 - { + init { $m = 400 } val n: Int - { + init { while (n == 0) { } $n = 10 @@ -183,7 +183,7 @@ class AnonymousInitializers(var a: String, val b: String) { } var p = 1 - { + init { p++ } } @@ -197,7 +197,7 @@ open class Open(a: Int, w: Int) {} class LocalValsVsProperties(val a: Int, w: Int) : Open(a, w) { val x : Int val y : Int - { + init { $x = 1 val b = x } @@ -212,7 +212,7 @@ class LocalValsVsProperties(val a: Int, w: Int) : Open(a, w) { } var xx = w var yy : Int - { + init { w += 1 $yy = w } @@ -222,13 +222,13 @@ class Outer() { val a : Int var b : Int - { + init { $a = 1 $b = 1 } inner class Inner() { - { + init { a++ b++ } @@ -250,7 +250,7 @@ class ClassObject() { default object { val x : Int - { + init { $x = 1 } @@ -267,7 +267,7 @@ fun foo() { val x : Int val y : Int val z : Int - { + init { $x = 1 $z = 3 } @@ -284,7 +284,7 @@ class TestObjectExpression() { val a = object { val x : Int val y : Int - { + init { if (true) x = 12 else @@ -307,7 +307,7 @@ class TestObjectExpression() { object TestObjectDeclaration { val x : Int val y : Int - { + init { $x = 1 } @@ -325,7 +325,7 @@ fun func() { val b = 1 val a = object { val x = b - { + init { b = 4 $b = 3 } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.kt index 03ffa4d6171..c6e6e7f82db 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt2330.kt @@ -9,7 +9,7 @@ class P { val other = P(); - { + init { x = 23 other.x = 4 } @@ -33,7 +33,7 @@ fun foo() { class R { val p = P(); - { + init { p.x = 42 } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.kt index bc62830cce4..aa75386d3a1 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt4405.kt @@ -14,7 +14,7 @@ val closure = { } class A { - { + init { fun foo(): Int { } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt index 1653a1cf1d4..d9a7ecbfb9d 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt510.kt @@ -4,7 +4,7 @@ package kt510 public open class Identifier1() { var field : Boolean - { + init { field = false; // error } } @@ -12,7 +12,7 @@ public open class Identifier1() { public open class Identifier2() { var field : Boolean - { + init { this.field = false; } } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt index 5c78f167f85..eb279e36d50 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt897.kt @@ -3,17 +3,17 @@ package kt897 class A() { - { + init { i = 11 } val i : Int? = null // must be an error - { + init { j = 1 } var j : Int = 2 - { + init { k = 3 } val k : Int diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.kt index 65e96304249..1ef2b89f2a5 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/localClasses.kt @@ -2,7 +2,7 @@ package f fun f() { class LocalClass() { - { + init { val x1 = "" // ok: unused fun loc1(): Int { diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.kt index 99bc9d5f2ac..f1938f3ff79 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/referenceToPropertyInitializer.kt @@ -12,7 +12,7 @@ open class A(val a: A) class TestObjectLiteral { val obj: A = object: A(obj) { - { + init { val x = obj } fun foo() { @@ -20,7 +20,7 @@ class TestObjectLiteral { } } val obj1: A = @l ( object: A(obj1) { - { + init { val x = obj1 } fun foo() = obj1 diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.kt index 550d9c41ad4..6958b958954 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/scopeOfAnonymousInitializer.kt @@ -1,5 +1,5 @@ class AnonymousInitializers(var a: String) { - { + init { a = "s" } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.kt index 6470bf9c71b..d006d747b35 100644 --- a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.kt +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInMemberOfLocalClass.kt @@ -5,7 +5,7 @@ fun test(x: Any) { fun foo(y: Any) { if (y !is String) return class Local { - { + init { x.length() y.length() } diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.kt b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.kt index 609dfa2ef13..b9cfcd6c29e 100644 --- a/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.kt +++ b/compiler/testData/diagnostics/tests/dataFlow/local/LocalClassInitializer.kt @@ -3,7 +3,7 @@ fun f(a: Any?) { if (a is B) { class C : X(a) { - { + init { a.foo() } } diff --git a/compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.kt b/compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.kt index 114cbaf8f32..9d168dc906e 100644 --- a/compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.kt +++ b/compiler/testData/diagnostics/tests/dataFlow/local/NestedLocalClass.kt @@ -3,7 +3,7 @@ fun test(x: Any) { class LocalOuter { inner class Local { - { + init { x.length() } } diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.kt b/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.kt index 9e233f03f45..eaf60600357 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/ambiguousObjectExpressionType.kt @@ -11,7 +11,7 @@ class Foo { private val privateProperty = object : MyClass(), MyTrait {} - { + init { privateProperty.f1() privateProperty.f2() } @@ -27,7 +27,7 @@ class Foo { private fun privateFunction() = object : MyClass(), MyTrait {} - { + init { privateFunction().f1() privateFunction().f2() } @@ -45,7 +45,7 @@ class Foo { class FooInner { private val privatePropertyInner = object : MyClass(), MyTrait {} - { + init { privatePropertyInner.f1() privatePropertyInner.f2() } @@ -61,7 +61,7 @@ class Foo { private fun privateFunctionInner() = object : MyClass(), MyTrait {} - { + init { privateFunctionInner().f1() privateFunctionInner().f2() } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt b/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt index 7e1b5c0ef94..01e9a91f009 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt @@ -1,8 +1,8 @@ class Foo() { - private val builder = StringBuilder("sdfsd"); + private val builder = StringBuilder("sdfsd") - { + init { } } diff --git a/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.kt b/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.kt index 8e5ac880ee1..046b3a70a24 100644 --- a/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.kt +++ b/compiler/testData/diagnostics/tests/infos/PropertiesWithBackingFields.kt @@ -50,7 +50,7 @@ class TestPCParameters(w : Int, x : Int, val y : Int, var val xx = w - { + init { w + 1 } diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.kt index 1ef06fa3ef2..0283fb87be7 100644 --- a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.kt +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/anonymousObjectsNested.kt @@ -6,7 +6,7 @@ inline fun inlineFunOnlyLocal(inlineOptions(ONLY_LOCAL_RETURN)p: () -> R) { val z = p(); - { + init { doCall { p() } @@ -25,9 +25,9 @@ inline fun inlineFunOnlyLocal(inlineOptions(ONLY_LOCAL_RETURN)p: () -> R) { inline fun inlineFun(p: () -> R) { val s = object { - val z = p(); + val z = p() - { + init { doCall { p() } diff --git a/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.kt b/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.kt index cec7452ce9e..b0cb260fad8 100644 --- a/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.kt +++ b/compiler/testData/diagnostics/tests/inner/referenceToSelfInLocal.kt @@ -3,7 +3,7 @@ fun f() { class MyClass() { - { + init { val x: MyClass = MyClass() } @@ -13,7 +13,7 @@ fun f() { } object MyObject { - { + init { val obj: MyObject = MyObject } } @@ -23,7 +23,7 @@ fun f() { val closure = { class MyClass { - { + init { val x: MyClass = MyClass() } } diff --git a/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt index 3835fb23bbc..7120e0cb5a6 100644 --- a/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt +++ b/compiler/testData/diagnostics/tests/modifiers/IllegalModifiers.kt @@ -69,15 +69,15 @@ abstract class IllegalModifiers5() { //Check illegal modifiers on anonymous initializers abstract class IllegalModifiers6() { - public {} - private {} - protected {} - vararg {} - abstract {} - open {} - final {} + public init {} + private init {} + protected init {} + vararg init {} + abstract init {} + open init {} + final init {} - public annotated {} + public annotated init {} - private IllegalModifiers6() {} + private IllegalModifiers6() init {} } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.kt index 528d88899ce..3aa126df2df 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt244.kt @@ -14,7 +14,7 @@ fun f(s: String?) { // more tests class A(a: String?) { val b = if (a != null) a.length() else 1 - { + init { if (a != null) { val c = a.length() } @@ -22,7 +22,7 @@ class A(a: String?) { val i : Int - { + init { if (a is String) { i = a.length() } diff --git a/compiler/testData/diagnostics/tests/objects/Objects.kt b/compiler/testData/diagnostics/tests/objects/Objects.kt index 4bd390a6273..67f9e21d0ac 100644 --- a/compiler/testData/diagnostics/tests/objects/Objects.kt +++ b/compiler/testData/diagnostics/tests/objects/Objects.kt @@ -19,7 +19,7 @@ package toplevelObjectDeclarations val x = A.foo() val y = object : Foo(x) { - { + init { x + 12 } diff --git a/compiler/testData/diagnostics/tests/regressions/Jet81.kt b/compiler/testData/diagnostics/tests/regressions/Jet81.kt index dfb6a09746b..7471dd22f7a 100644 --- a/compiler/testData/diagnostics/tests/regressions/Jet81.kt +++ b/compiler/testData/diagnostics/tests/regressions/Jet81.kt @@ -15,7 +15,7 @@ object A { class Test2 { private val a = object { - { + init { b + 1 } val x = b diff --git a/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.kt b/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.kt index 721fa3e741a..707c5960b5d 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt1639-JFrame.kt @@ -3,7 +3,7 @@ package test import javax.swing.JFrame class KFrame() : JFrame() { - { + init { val x = this.rootPaneCheckingEnabled // make sure field is visible } } diff --git a/compiler/testData/diagnostics/tests/regressions/kt3731.kt b/compiler/testData/diagnostics/tests/regressions/kt3731.kt index da5751f21ce..de1728d6c84 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt3731.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt3731.kt @@ -7,7 +7,7 @@ class A { class B { class D { - { + init { A().bar { this.foo() foo() diff --git a/compiler/testData/diagnostics/tests/regressions/kt575.kt b/compiler/testData/diagnostics/tests/regressions/kt575.kt index 0a1fd8f01d1..d75b221e2a4 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt575.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt575.kt @@ -11,7 +11,7 @@ class Creature() { object A { var bbb : Int - { + init { $bbb = 1 } } @@ -19,12 +19,12 @@ class Creature() { class C() { var ccc : Int - { + init { $ccc = 2 } } - { + init { Creature.numCreated++ // Error A.bbb++ C().ccc++ diff --git a/compiler/testData/diagnostics/tests/scopes/kt1244.kt b/compiler/testData/diagnostics/tests/scopes/kt1244.kt index 16bc89dc4ba..ce2fa037917 100644 --- a/compiler/testData/diagnostics/tests/scopes/kt1244.kt +++ b/compiler/testData/diagnostics/tests/scopes/kt1244.kt @@ -7,7 +7,7 @@ class A { } class B() { - { + init { A().a = "Hello" } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/kt37.kt b/compiler/testData/diagnostics/tests/scopes/kt37.kt index 8799410aa0d..761a6fa6085 100644 --- a/compiler/testData/diagnostics/tests/scopes/kt37.kt +++ b/compiler/testData/diagnostics/tests/scopes/kt37.kt @@ -4,7 +4,7 @@ package kt37 class C() { private var f: Int - { + init { f = 610 } } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt new file mode 100644 index 00000000000..03df7843893 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt @@ -0,0 +1,10 @@ +class A { + val x: Int + val y: Int + { + x = 1 + } + init { + y = 1 + } +} diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.txt b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.txt new file mode 100644 index 00000000000..4be4604d583 --- /dev/null +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.txt @@ -0,0 +1,10 @@ +package + +internal final class A { + public constructor A() + internal final val x: kotlin.Int + internal final val y: kotlin.Int + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.kt b/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.kt index 63539f6e7aa..df1e27c5d93 100644 --- a/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.kt +++ b/compiler/testData/diagnostics/tests/subtyping/memberAnonymousObjects.kt @@ -1,6 +1,6 @@ class Test { private var x = object {}; - { + init { x = object {} } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/varargs/kt1838-param.kt b/compiler/testData/diagnostics/tests/varargs/kt1838-param.kt index 8a577f499d5..39423b8d0a6 100644 --- a/compiler/testData/diagnostics/tests/varargs/kt1838-param.kt +++ b/compiler/testData/diagnostics/tests/varargs/kt1838-param.kt @@ -1,5 +1,5 @@ class A(vararg t : Int) { - { + init { val t1 : IntArray = t } } diff --git a/compiler/testData/diagnostics/tests/varargs/kt1838-val.kt b/compiler/testData/diagnostics/tests/varargs/kt1838-val.kt index c45857f56d7..b152fcadc0c 100644 --- a/compiler/testData/diagnostics/tests/varargs/kt1838-val.kt +++ b/compiler/testData/diagnostics/tests/varargs/kt1838-val.kt @@ -1,5 +1,5 @@ class A(vararg val t : Int) { - { + init { val t1 : IntArray = t } } diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt index 866a159357a..0ef5fbaa321 100644 --- a/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/FunctionCall.kt @@ -7,7 +7,7 @@ class Test { fun apply(i: I) {} - { + init { foo() this.foo() } diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt index c932acb8b05..f85e9a9b2f2 100644 --- a/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/GetVal.kt @@ -4,7 +4,7 @@ fun with(receiver: T, f: T.() -> R): R = receiver.f() class Test { private val i: I = getT() - ;{ + init { apply(i) apply(this.i) } diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt index bc7760358b2..426f1fca673 100644 --- a/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/SetVar.kt @@ -5,7 +5,7 @@ class Test { private var i: I = getT() private val j: I - ;{ + init { j = getT() i = getT() this.i = getT() diff --git a/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt index 10c869b1db7..486f11c43f1 100644 --- a/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt +++ b/compiler/testData/diagnostics/tests/variance/privateToThis/ValReassigned.kt @@ -3,7 +3,7 @@ fun getT(): T = null!! class A(init: I) { private val i: I - { + init { i = getT() } @@ -12,7 +12,7 @@ class A(init: I) { private var i4 = getT() - ;{ + init { i2 = getT() i3 = init i4 = i3 diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index c357feaa9bf..08dc179dbd4 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -10469,6 +10469,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("expectedInitKeywordOnInitializer.kt") + public void testExpectedInitKeywordOnInitializer() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/expectedInitKeywordOnInitializer.kt"); + doTest(fileName); + } + @TestMetadata("expectedPrimaryConstructorCall.kt") public void testExpectedPrimaryConstructorCall() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.kt"); diff --git a/idea/testData/checker/AnonymousInitializers.kt b/idea/testData/checker/AnonymousInitializers.kt index 841add1fad9..2fbc177d6eb 100644 --- a/idea/testData/checker/AnonymousInitializers.kt +++ b/idea/testData/checker/AnonymousInitializers.kt @@ -1,18 +1,18 @@ trait NoC { - { + init { } val a : Int get() = 1 - { + init { } } class WithC() { val x : Int - { + init { $x = 1 $y = 2 val b = x @@ -21,7 +21,7 @@ class WithC() { val a : Int get() = 1 - { + init { val z = b val zz = x val zzz = $a diff --git a/idea/testData/checker/Objects.kt b/idea/testData/checker/Objects.kt index 0a00cd792bb..3e8c0347367 100644 --- a/idea/testData/checker/Objects.kt +++ b/idea/testData/checker/Objects.kt @@ -18,7 +18,7 @@ package toplevelObjectDeclarations val x = A.foo() val y = object : Foo(x) { - { + init { x + 12 } diff --git a/idea/testData/checker/Properties.kt b/idea/testData/checker/Properties.kt index 5824b335560..684d62ada95 100644 --- a/idea/testData/checker/Properties.kt +++ b/idea/testData/checker/Properties.kt @@ -16,7 +16,7 @@ class Test() { var a : Int = 111 var b : Int get() = $a; set(x) {a = x; $a = x} - { + init { $b = $a $a = $b a = $b diff --git a/idea/testData/checker/infos/PropertiesWithBackingFields.kt b/idea/testData/checker/infos/PropertiesWithBackingFields.kt index 8c7b8357237..ea997261f10 100644 --- a/idea/testData/checker/infos/PropertiesWithBackingFields.kt +++ b/idea/testData/checker/infos/PropertiesWithBackingFields.kt @@ -46,7 +46,7 @@ class TestPCParameters(w : Int, x : Int, val y : val xx = w - { + init { w + 1 } diff --git a/idea/testData/checker/regression/ScopeForSecondaryConstructors.kt b/idea/testData/checker/regression/ScopeForSecondaryConstructors.kt index 00c6fddb76e..60ee52ef9e9 100644 --- a/idea/testData/checker/regression/ScopeForSecondaryConstructors.kt +++ b/idea/testData/checker/regression/ScopeForSecondaryConstructors.kt @@ -1,5 +1,5 @@ class Foo(var bar : Int, var barr : Int, var barrr : Int) { - { + init { bar = 1 barr = 1 barrr = 1 @@ -7,7 +7,7 @@ this : Foo } - { + init { bar = 1 this.bar 1 : Int diff --git a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInClassObjectInitializer.kt b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInClassObjectInitializer.kt index 497be5f05b9..0ca37dd660a 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInClassObjectInitializer.kt +++ b/idea/testData/quickfix/createFromUsage/createVariable/parameter/beforeInClassObjectInitializer.kt @@ -6,7 +6,7 @@ class A { default object { - { + init { val t: Int = foo } }