From cd56678467b382e527e224a97b71bb8c646cc051 Mon Sep 17 00:00:00 2001 From: Peter Tseng Date: Fri, 8 Mar 2013 02:11:58 -0500 Subject: [PATCH] Change ANONYMOUS_INITIALIZER from _WITHOUT_CONSTRUCTOR to _IN_TRAIT "since we made all classes have constructors some time ago", this error doesn't even trigger on a class such as: class testClass { {} } It does trigger on a trait: trait testTrait { {} } Therefore, the error message should be changed to reflect the new behavior. However, an actual quickfix for this will be more involved. It is not a good idea to simply delete the initializer, since it could contain valuable code that the user wants to keep. --- .../src/org/jetbrains/jet/lang/diagnostics/Errors.java | 2 +- .../jet/lang/diagnostics/rendering/DefaultErrorMessages.java | 2 +- .../src/org/jetbrains/jet/lang/resolve/BodyResolver.java | 2 +- compiler/testData/diagnostics/tests/AnonymousInitializers.kt | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 44012511fea..253f6ff5975 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -524,7 +524,7 @@ public interface Errors { DiagnosticFactory0 NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY = DiagnosticFactory0.create(ERROR, DECLARATION_WITH_BODY); - DiagnosticFactory0 ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 ANONYMOUS_INITIALIZER_IN_TRAIT = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 NO_THIS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 NAMESPACE_IS_NOT_AN_EXPRESSION = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java index 9b8f6da5878..5bda932b13e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java @@ -305,7 +305,7 @@ public class DefaultErrorMessages { MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", TO_STRING); MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", TO_STRING); - MAP.put(ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR, "Anonymous initializers are only allowed in the presence of a primary constructor"); + MAP.put(ANONYMOUS_INITIALIZER_IN_TRAIT, "Anonymous initializers are not allowed in traits"); MAP.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable"); MAP.put(REDUNDANT_NULLABLE, "Redundant '?'"); MAP.put(BASE_WITH_NULLABLE_UPPER_BOUND, "''{0}'' has a nullable upper bound. " + diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java index 9dab74d0616..7aa9960d1fc 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java @@ -346,7 +346,7 @@ public class BodyResolver { } else { for (JetClassInitializer anonymousInitializer : anonymousInitializers) { - trace.report(ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR.on(anonymousInitializer)); + trace.report(ANONYMOUS_INITIALIZER_IN_TRAIT.on(anonymousInitializer)); } } } diff --git a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt index cb00fef671e..32687cba94b 100644 --- a/compiler/testData/diagnostics/tests/AnonymousInitializers.kt +++ b/compiler/testData/diagnostics/tests/AnonymousInitializers.kt @@ -1,11 +1,11 @@ trait NoC { - { + { } val a : Int get() = 1 - { + { } }