From f88cd5ed3d4323ffc048b2d0fd19140eff3ca530 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 31 May 2017 12:50:11 +0300 Subject: [PATCH] Allow 'lateinit' modifier on local variables --- .../jetbrains/kotlin/resolve/ModifiersChecker.kt | 2 +- .../tests/lateinit/modifierApplicability.kt | 2 +- .../properties/localLateinit/localLateinit.kt | 5 +++++ .../properties/localLateinit/localLateinit.txt | 3 +++ .../kotlin/checkers/DiagnosticsTestGenerated.java | 15 +++++++++++++++ 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.kt create mode 100644 compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt index 904f8902030..02de5e34193 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt @@ -74,7 +74,7 @@ object ModifierCheckerCore { REIFIED_KEYWORD to EnumSet.of(TYPE_PARAMETER), VARARG_KEYWORD to EnumSet.of(VALUE_PARAMETER, PROPERTY_PARAMETER), COMPANION_KEYWORD to EnumSet.of(OBJECT), - LATEINIT_KEYWORD to EnumSet.of(MEMBER_PROPERTY), + LATEINIT_KEYWORD to EnumSet.of(MEMBER_PROPERTY, LOCAL_VARIABLE), DATA_KEYWORD to EnumSet.of(CLASS_ONLY, LOCAL_CLASS), INLINE_KEYWORD to EnumSet.of(FUNCTION, PROPERTY, PROPERTY_GETTER, PROPERTY_SETTER), NOINLINE_KEYWORD to EnumSet.of(VALUE_PARAMETER), diff --git a/compiler/testData/diagnostics/tests/lateinit/modifierApplicability.kt b/compiler/testData/diagnostics/tests/lateinit/modifierApplicability.kt index ac699462bf6..2370a79616d 100644 --- a/compiler/testData/diagnostics/tests/lateinit/modifierApplicability.kt +++ b/compiler/testData/diagnostics/tests/lateinit/modifierApplicability.kt @@ -19,7 +19,7 @@ public abstract class A(la private set fun a() { - lateinit var a: String + lateinit var a: String } lateinit var e1: V diff --git a/compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.kt b/compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.kt new file mode 100644 index 00000000000..ed402a1eb64 --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.kt @@ -0,0 +1,5 @@ +fun test() { + lateinit var s: String + s = "" + s.length +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.txt b/compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.txt new file mode 100644 index 00000000000..93e27f34c8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.txt @@ -0,0 +1,3 @@ +package + +public fun test(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 48238a5d028..f9cb68aaf1c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -16254,6 +16254,21 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } } + + @TestMetadata("compiler/testData/diagnostics/tests/properties/localLateinit") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class LocalLateinit extends AbstractDiagnosticsTest { + public void testAllFilesPresentInLocalLateinit() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/properties/localLateinit"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("localLateinit.kt") + public void testLocalLateinit() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/properties/localLateinit/localLateinit.kt"); + doTest(fileName); + } + } } @TestMetadata("compiler/testData/diagnostics/tests/qualifiedExpression")