From 8d88109c005ced2aed07c6de26a94f967718d453 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 19 Oct 2015 11:55:59 +0300 Subject: [PATCH] Underscore names are now forbidden --- .../org/jetbrains/kotlin/diagnostics/Errors.java | 2 +- .../rendering/DefaultErrorMessages.java | 2 +- .../kotlin/resolve/UnderscoreChecker.kt | 2 +- .../kotlin/resolve/lazy/LazyImportScope.kt | 2 +- compiler/testData/codegen/box/classes/kt508.kt | 6 +++--- compiler/testData/codegen/box/objects/kt535.kt | 4 ++-- .../testData/diagnostics/tests/Underscore.kt | 16 ++++++++-------- .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index aa70814073b..10c2997c8a5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -558,7 +558,7 @@ public interface Errors { DiagnosticFactory1 COMPARE_TO_TYPE_MISMATCH = DiagnosticFactory1.create(ERROR); - DiagnosticFactory0 UNDERSCORE_IS_DEPRECATED = DiagnosticFactory0.create(WARNING); + DiagnosticFactory0 UNDERSCORE_IS_RESERVED = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 INVALID_CHARACTERS = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 INAPPLICABLE_OPERATOR_MODIFIER = DiagnosticFactory0.create(WARNING); 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 0bcf585b070..4fe4a3caad0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -365,7 +365,7 @@ public class DefaultErrorMessages { MAP.put(COMPARE_TO_TYPE_MISMATCH, "''compareTo()'' must return kotlin.Int, but returns {0}", RENDER_TYPE); - MAP.put(UNDERSCORE_IS_DEPRECATED, "Names _, __, ___, ..., are deprecated"); + MAP.put(UNDERSCORE_IS_RESERVED, "Names _, __, ___, ..., are reserved in Kotlin"); MAP.put(INVALID_CHARACTERS, "Name {0}", STRING); MAP.put(INAPPLICABLE_OPERATOR_MODIFIER, "'operator' modifier is inapplicable on this function"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/UnderscoreChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/UnderscoreChecker.kt index 07b7d8e87ef..8c4bcc024c2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/UnderscoreChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/UnderscoreChecker.kt @@ -30,7 +30,7 @@ object UnderscoreChecker : DeclarationChecker { fun checkIdentifier(identifier: PsiElement?, diagnosticHolder: DiagnosticSink) { if (identifier == null || identifier.text.isEmpty()) return if (identifier.text.all { it == '_' }) { - diagnosticHolder.report(Errors.UNDERSCORE_IS_DEPRECATED.on(identifier)) + diagnosticHolder.report(Errors.UNDERSCORE_IS_RESERVED.on(identifier)) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt index 96637581b8a..ab6808269d5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/LazyImportScope.kt @@ -102,7 +102,7 @@ class LazyImportResolver( } for ((alias, import) in explicitClassImports.entries()) { if (alias.all { it == '_' }) { - traceForImportResolve.report(Errors.UNDERSCORE_IS_DEPRECATED.on(import)) + traceForImportResolve.report(Errors.UNDERSCORE_IS_RESERVED.on(import)) } } for (alias in explicitClassImports.keySet()) { diff --git a/compiler/testData/codegen/box/classes/kt508.kt b/compiler/testData/codegen/box/classes/kt508.kt index ce2a4ba643e..2f55f67acdd 100644 --- a/compiler/testData/codegen/box/classes/kt508.kt +++ b/compiler/testData/codegen/box/classes/kt508.kt @@ -4,9 +4,9 @@ public open class Identifier() { private var myNullable : Boolean = true companion object { open public fun init(isNullable : Boolean) : Identifier { - val __ = Identifier() - __.myNullable = isNullable - return __ + val id = Identifier() + id.myNullable = isNullable + return id } } } diff --git a/compiler/testData/codegen/box/objects/kt535.kt b/compiler/testData/codegen/box/objects/kt535.kt index 693d73f7682..21f8e802985 100644 --- a/compiler/testData/codegen/box/objects/kt535.kt +++ b/compiler/testData/codegen/box/objects/kt535.kt @@ -5,8 +5,8 @@ class Identifier(t : T?, myHasDollar : Boolean) { companion object { open public fun init(name : T?) : Identifier { - val __ = Identifier(name, false) - return __ + val id = Identifier(name, false) + return id } } init { diff --git a/compiler/testData/diagnostics/tests/Underscore.kt b/compiler/testData/diagnostics/tests/Underscore.kt index db8f1220b3a..d2e98d02a5b 100644 --- a/compiler/testData/diagnostics/tests/Underscore.kt +++ b/compiler/testData/diagnostics/tests/Underscore.kt @@ -1,20 +1,20 @@ // !DIAGNOSTICS: -DEPRECATION -import kotlin.Deprecated as ___ +import kotlin.Deprecated as ___ @___("") data class Pair(val x: Int, val y: Int) -class _<________> -val ______ = _() +class _<________> +val ______ = _() -fun __(___: Int, y: _?): Int { - val (x, __________) = Pair(___ - 1, 42) - val ____ = x +fun __(___: Int, y: _?): Int { + val (x, __________) = Pair(___ - 1, 42) + val ____ = x // in backquotes: allowed val `_` = __________ - __@ return if (y != null) __(____, y) else __(`_`, ______) + __@ return if (y != null) __(____, y) else __(`_`, ______) } fun doIt(f: (Any?) -> Any?) = f(null) -val something = doIt { __ -> __ } \ No newline at end of file +val something = doIt { __ -> __ } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index bd12e79ab17..e516b20af48 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -330,7 +330,7 @@ public class QuickFixRegistrar : QuickFixContributor { OPERATOR_MODIFIER_REQUIRED.registerFactory(AddModifierFixFactory(JetTokens.OPERATOR_KEYWORD)) INFIX_MODIFIER_REQUIRED.registerFactory(AddModifierFixFactory(JetTokens.INFIX_KEYWORD)) - UNDERSCORE_IS_DEPRECATED.registerFactory(RenameUnderscoreFix) + UNDERSCORE_IS_RESERVED.registerFactory(RenameUnderscoreFix) CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.registerFactory(AddTypeToLHSOfCallableReferenceFix)