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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user