Recovery for initializer if no LBRACE
- If no LBRACE after 'init' keyword parse initializer without body - Made getBody() nullable, appropriate checks added
This commit is contained in:
@@ -330,7 +330,10 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
||||
}
|
||||
}
|
||||
else if (declaration instanceof JetClassInitializer) {
|
||||
codegen.invoke().gen(((JetClassInitializer) declaration).getBody(), Type.VOID_TYPE);
|
||||
JetExpression body = ((JetClassInitializer) declaration).getBody();
|
||||
if (body != null) {
|
||||
codegen.invoke().gen(body, Type.VOID_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -846,7 +846,12 @@ public class JetParsing extends AbstractJetParsing {
|
||||
}
|
||||
else if (at(INIT_KEYWORD)) {
|
||||
advance(); // init
|
||||
parseBlock();
|
||||
if (at(LBRACE)) {
|
||||
parseBlock();
|
||||
}
|
||||
else {
|
||||
mark().error("Expecting '{' after 'init'");
|
||||
}
|
||||
declType = ANONYMOUS_INITIALIZER;
|
||||
}
|
||||
else if (at(CONSTRUCTOR_KEYWORD)) {
|
||||
|
||||
@@ -38,11 +38,9 @@ public class JetClassInitializer extends JetDeclarationStub<KotlinPlaceHolderStu
|
||||
return visitor.visitAnonymousInitializer(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public JetExpression getBody() {
|
||||
JetExpression body = findChildByClass(JetExpression.class);
|
||||
assert body != null;
|
||||
return body;
|
||||
return findChildByClass(JetExpression.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -458,7 +458,10 @@ public class BodyResolver {
|
||||
|
||||
JetScope scopeForInitializers = classDescriptor.getScopeForInitializerResolution();
|
||||
if (!classDescriptor.getConstructors().isEmpty()) {
|
||||
expressionTypingServices.getType(scopeForInitializers, anonymousInitializer.getBody(), NO_EXPECTED_TYPE, c.getOuterDataFlowInfo(), trace);
|
||||
JetExpression body = anonymousInitializer.getBody();
|
||||
if (body != null) {
|
||||
expressionTypingServices.getType(scopeForInitializers, body, NO_EXPECTED_TYPE, c.getOuterDataFlowInfo(), trace);
|
||||
}
|
||||
processModifiersOnInitializer(anonymousInitializer, scopeForInitializers);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class A {
|
||||
init
|
||||
}
|
||||
|
||||
class B {
|
||||
Ann init
|
||||
val x = 1
|
||||
init
|
||||
fun foo() {}
|
||||
init
|
||||
init
|
||||
init {}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
JetFile: initRecovery.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
CLASS
|
||||
PsiElement(class)('class')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('A')
|
||||
PsiWhiteSpace(' ')
|
||||
CLASS_BODY
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
ANONYMOUS_INITIALIZER
|
||||
PsiElement(init)('init')
|
||||
PsiErrorElement:Expecting '{' after 'init'
|
||||
<empty list>
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n\n')
|
||||
CLASS
|
||||
PsiElement(class)('class')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('B')
|
||||
PsiWhiteSpace(' ')
|
||||
CLASS_BODY
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiWhiteSpace('\n ')
|
||||
ANONYMOUS_INITIALIZER
|
||||
MODIFIER_LIST
|
||||
ANNOTATION_ENTRY
|
||||
CONSTRUCTOR_CALLEE
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('Ann')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(init)('init')
|
||||
PsiErrorElement:Expecting '{' after 'init'
|
||||
<empty list>
|
||||
PsiWhiteSpace('\n ')
|
||||
PROPERTY
|
||||
PsiElement(val)('val')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('x')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('1')
|
||||
PsiWhiteSpace('\n ')
|
||||
ANONYMOUS_INITIALIZER
|
||||
PsiElement(init)('init')
|
||||
PsiErrorElement:Expecting '{' after 'init'
|
||||
<empty list>
|
||||
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 ')
|
||||
ANONYMOUS_INITIALIZER
|
||||
PsiElement(init)('init')
|
||||
PsiErrorElement:Expecting '{' after 'init'
|
||||
<empty list>
|
||||
PsiWhiteSpace('\n ')
|
||||
ANONYMOUS_INITIALIZER
|
||||
PsiElement(init)('init')
|
||||
PsiErrorElement:Expecting '{' after 'init'
|
||||
<empty list>
|
||||
PsiWhiteSpace('\n ')
|
||||
ANONYMOUS_INITIALIZER
|
||||
PsiElement(init)('init')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -1564,6 +1564,12 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("initRecovery.kt")
|
||||
public void testInitRecovery() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/initRecovery.kt");
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("InvalidCharInSingleLineLambda.kt")
|
||||
public void testInvalidCharInSingleLineLambda() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.kt");
|
||||
|
||||
Reference in New Issue
Block a user