From 508c7a58b60bbacd2ae46328f794627f0db788cf Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 9 Apr 2015 19:20:15 +0300 Subject: [PATCH] KT-7377 Throwable: Empty PSI elements should not be passed to createDescriptor from UnusedReceiverParameterInspection #KT-7377 fixed --- .../jetbrains/kotlin/parsing/JetParsing.java | 2 +- compiler/testData/psi/recovery/BareVal.kt | 11 ++++ compiler/testData/psi/recovery/BareVal.txt | 56 +++++++++++++++++++ .../parsing/JetParsingTestGenerated.java | 6 ++ .../unusedReceiverParameter/kt7377.kt | 9 +++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/psi/recovery/BareVal.kt create mode 100644 compiler/testData/psi/recovery/BareVal.txt create mode 100644 idea/testData/inspections/unusedReceiverParameter/kt7377.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java index e74f0bb572b..21508bbaef7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/JetParsing.java @@ -1366,7 +1366,7 @@ public class JetParsing extends AbstractJetParsing { } private boolean definitelyOutOfReceiver() { - return atSet(EQ, COLON, LBRACE, BY_KEYWORD) || atSet(TOPLEVEL_OBJECT_FIRST); + return atSet(EQ, COLON, LBRACE, RBRACE, BY_KEYWORD) || atSet(TOPLEVEL_OBJECT_FIRST); } /* diff --git a/compiler/testData/psi/recovery/BareVal.kt b/compiler/testData/psi/recovery/BareVal.kt new file mode 100644 index 00000000000..8bb9da957e1 --- /dev/null +++ b/compiler/testData/psi/recovery/BareVal.kt @@ -0,0 +1,11 @@ +class Clazz { + val +} + +fun f() { + a.b() +} + +class Clazz { + val +} diff --git a/compiler/testData/psi/recovery/BareVal.txt b/compiler/testData/psi/recovery/BareVal.txt new file mode 100644 index 00000000000..eaebe0d2c4a --- /dev/null +++ b/compiler/testData/psi/recovery/BareVal.txt @@ -0,0 +1,56 @@ +JetFile: BareVal.kt + PACKAGE_DIRECTIVE + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Clazz') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('f') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('b') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Clazz') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java index 37eae242744..5d361d731cf 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java @@ -1428,6 +1428,12 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/psi/recovery"), Pattern.compile("^(.*)\\.kts?$"), true); } + @TestMetadata("BareVal.kt") + public void testBareVal() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/BareVal.kt"); + doParsingTest(fileName); + } + @TestMetadata("DoWhileWithEmptyCondition.kt") public void testDoWhileWithEmptyCondition() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/DoWhileWithEmptyCondition.kt"); diff --git a/idea/testData/inspections/unusedReceiverParameter/kt7377.kt b/idea/testData/inspections/unusedReceiverParameter/kt7377.kt new file mode 100644 index 00000000000..bca2040b34a --- /dev/null +++ b/idea/testData/inspections/unusedReceiverParameter/kt7377.kt @@ -0,0 +1,9 @@ +class Clazz(foo: String) { + val foo = foo + + val +} + +fun main(args: Array) { + System.setProperty("java.awt.headless", "true") +} \ No newline at end of file