diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java index 79af3435c21..5da9ef73611 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java @@ -53,7 +53,7 @@ public class KotlinParsing extends AbstractKotlinParsing { private static final TokenSet CLASS_NAME_RECOVERY_SET = TokenSet.orSet(TokenSet.create(LT, LPAR, COLON, LBRACE), TOP_LEVEL_DECLARATION_FIRST); private static final TokenSet TYPE_PARAMETER_GT_RECOVERY_SET = TokenSet.create(WHERE_KEYWORD, LPAR, COLON, LBRACE, GT); - private static final TokenSet PARAMETER_NAME_RECOVERY_SET = TokenSet.create(COLON, EQ, COMMA, RPAR); + private static final TokenSet PARAMETER_NAME_RECOVERY_SET = TokenSet.create(COLON, EQ, COMMA, RPAR, VAL_KEYWORD, VAR_KEYWORD); private static final TokenSet PACKAGE_NAME_RECOVERY_SET = TokenSet.create(DOT, EOL_OR_SEMICOLON); private static final TokenSet IMPORT_RECOVERY_SET = TokenSet.create(AS_KEYWORD, DOT, EOL_OR_SEMICOLON); private static final TokenSet TYPE_REF_FIRST = TokenSet.create(LBRACKET, IDENTIFIER, LPAR, HASH, DYNAMIC_KEYWORD); diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.kt new file mode 100644 index 00000000000..054ff973a76 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.kt @@ -0,0 +1,43 @@ +// VAL +class A( + val + val x: Int, + val + private val z: Int, + val +) + +val +fun foo() {} + +class B { + val + fun foo() {} + + fun bar() { + val + fun foo() {} + } +} + +// VAR +class C( + var + val x: Int, + var + private val z: Int, + var +) + +var +fun baz() {} + +class D { + var + fun foo() {} + + fun bar() { + var + fun foo() {} + } +} diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.txt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.txt new file mode 100644 index 00000000000..956f577ce08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.txt @@ -0,0 +1,50 @@ +package + +public val : [ERROR : No type, no body] +public var : [ERROR : No type, no body] +public fun baz(): kotlin.Unit +public fun foo(): kotlin.Unit + +public final class A { + public constructor A(/*0*/ : [ERROR : Type annotation was missing for parameter ], /*1*/ x: kotlin.Int, /*2*/ private: [ERROR : Type annotation was missing for parameter private], /*3*/ z: kotlin.Int, /*4*/ : [ERROR : Type annotation was missing for parameter ]) + public final val : [ERROR : Annotation is absent] + public final val : [ERROR : Annotation is absent] + public final val private: [ERROR : Annotation is absent] + public final val x: kotlin.Int + public final val z: 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 +} + +public final class B { + public constructor B() + public final val : [ERROR : No type, no body] + public final fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final class C { + public constructor C(/*0*/ : [ERROR : Type annotation was missing for parameter ], /*1*/ x: kotlin.Int, /*2*/ private: [ERROR : Type annotation was missing for parameter private], /*3*/ z: kotlin.Int, /*4*/ : [ERROR : Type annotation was missing for parameter ]) + public final var : [ERROR : Annotation is absent] + public final var : [ERROR : Annotation is absent] + public final var private: [ERROR : Annotation is absent] + public final val x: kotlin.Int + public final val z: 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 +} + +public final class D { + public constructor D() + public final var : [ERROR : No type, no body] + public final fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(): kotlin.Unit + 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/psi/recovery/ValNoName.kt b/compiler/testData/psi/recovery/ValNoName.kt new file mode 100644 index 00000000000..0b4e7b80d4f --- /dev/null +++ b/compiler/testData/psi/recovery/ValNoName.kt @@ -0,0 +1,43 @@ +// VAL +class A( + val + val x: Int, + val + private val z: Int, + val +) + +val +fun foo() {} + +class B { + val + fun foo() {} + + fun bar() { + val + fun foo() {} + } +} + +// VAR +class C( + var + val x: Int, + var + private val z: Int, + var +) + +var +fun baz() {} + +class D { + var + fun foo() {} + + fun bar() { + var + fun foo() {} + } +} diff --git a/compiler/testData/psi/recovery/ValNoName.txt b/compiler/testData/psi/recovery/ValNoName.txt new file mode 100644 index 00000000000..d9601b5bba3 --- /dev/null +++ b/compiler/testData/psi/recovery/ValNoName.txt @@ -0,0 +1,258 @@ +JetFile: ValNoName.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + CLASS + PsiComment(EOL_COMMENT)('// VAL') + PsiWhiteSpace('\n') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A') + PRIMARY_CONSTRUCTOR + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiErrorElement:Parameter name expected + + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace('\n ') + PsiElement(IDENTIFIER)('private') + PsiErrorElement:Parameters must have type annotation + + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('z') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiErrorElement:Parameter name expected + + PsiWhiteSpace('\n') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(val)('val') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('B') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiComment(EOL_COMMENT)('// VAR') + PsiWhiteSpace('\n') + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('C') + PRIMARY_CONSTRUCTOR + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(var)('var') + PsiErrorElement:Parameter name expected + + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(var)('var') + PsiWhiteSpace('\n ') + PsiElement(IDENTIFIER)('private') + PsiErrorElement:Parameters must have type annotation + + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('z') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace('\n ') + VALUE_PARAMETER + PsiElement(var)('var') + PsiErrorElement:Parameter name expected + + PsiWhiteSpace('\n') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n\n') + PROPERTY + PsiElement(var)('var') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('baz') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('D') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(var)('var') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(var)('var') + PsiErrorElement:Expecting property name or receiver type + + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 1bb1d10fa0c..bfc5c45987b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -8776,6 +8776,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/typeReferenceError.kt"); doTest(fileName); } + + @TestMetadata("valNoName.kt") + public void testValNoName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/valNoName.kt"); + doTest(fileName); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java index e43dca1e4a6..133646a63c0 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java @@ -2262,6 +2262,12 @@ public class ParsingTestGenerated extends AbstractParsingTest { doParsingTest(fileName); } + @TestMetadata("ValNoName.kt") + public void testValNoName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/recovery/ValNoName.kt"); + doParsingTest(fileName); + } + @TestMetadata("ValueParameterNoTypeRecovery.kt") public void testValueParameterNoTypeRecovery() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.kt");