NPE on unfinished function declaration fixed
This commit is contained in:
@@ -406,7 +406,9 @@ public class TopDownAnalyzer {
|
|||||||
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
||||||
for (JetAnnotationEntry annotationEntry : annotationEntries) {
|
for (JetAnnotationEntry annotationEntry : annotationEntries) {
|
||||||
AnnotationDescriptor annotationDescriptor = trace.get(ANNOTATION, annotationEntry);
|
AnnotationDescriptor annotationDescriptor = trace.get(ANNOTATION, annotationEntry);
|
||||||
annotationResolver.resolveAnnotationStub(mutableClassDescriptor.getScopeForSupertypeResolution(), annotationEntry, annotationDescriptor);
|
if (annotationDescriptor != null) {
|
||||||
|
annotationResolver.resolveAnnotationStub(mutableClassDescriptor.getScopeForSupertypeResolution(), annotationEntry, annotationDescriptor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -964,14 +966,15 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void checkFunctionCorrectness(JetNamedFunction function, FunctionDescriptor functionDescriptor, DeclarationDescriptor containingDescriptor) {
|
protected void checkFunctionCorrectness(JetNamedFunction function, FunctionDescriptor functionDescriptor, DeclarationDescriptor containingDescriptor) {
|
||||||
|
PsiElement nameIdentifier = function.getNameIdentifier();
|
||||||
if (containingDescriptor instanceof ClassDescriptor) {
|
if (containingDescriptor instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDescriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDescriptor;
|
||||||
if (functionDescriptor.getModifiers().isAbstract() && !classDescriptor.isAbstract()) {
|
if (functionDescriptor.getModifiers().isAbstract() && !classDescriptor.isAbstract()) {
|
||||||
trace.getErrorHandler().genericError(function.getModifierList().getModifierNode(JetTokens.ABSTRACT_KEYWORD),
|
trace.getErrorHandler().genericError(function.getModifierList().getModifierNode(JetTokens.ABSTRACT_KEYWORD),
|
||||||
"Abstract method " + function.getName() + " in non-abstract class " + classDescriptor.getName());
|
"Abstract method " + function.getName() + " in non-abstract class " + classDescriptor.getName());
|
||||||
}
|
}
|
||||||
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract()) {
|
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract() && nameIdentifier != null) {
|
||||||
trace.getErrorHandler().genericError(function.getNameIdentifier().getNode(), "Method without body must be abstract");
|
trace.getErrorHandler().genericError(nameIdentifier.getNode(), "Method " + function.getName() + " without body must be abstract");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -979,8 +982,8 @@ public class TopDownAnalyzer {
|
|||||||
trace.getErrorHandler().genericError(function.getModifierList().getModifierNode(JetTokens.ABSTRACT_KEYWORD),
|
trace.getErrorHandler().genericError(function.getModifierList().getModifierNode(JetTokens.ABSTRACT_KEYWORD),
|
||||||
"Global function " + function.getName() + " can not be abstract");
|
"Global function " + function.getName() + " can not be abstract");
|
||||||
}
|
}
|
||||||
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract()) {
|
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract() && nameIdentifier != null) {
|
||||||
trace.getErrorHandler().genericError(function.getNameIdentifier().getNode(), "Global function must have body");
|
trace.getErrorHandler().genericError(nameIdentifier.getNode(), "Global function " + function.getName() + " must have body");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,22 @@ fun blockReturnValueTypeMatch() : Int {
|
|||||||
fun blockNoReturnIfValDeclaration(): Int {
|
fun blockNoReturnIfValDeclaration(): Int {
|
||||||
<error>val x = 1</error>
|
<error>val x = 1</error>
|
||||||
}
|
}
|
||||||
|
fun blockNoReturnIfEmptyIf(): Int {
|
||||||
|
if (1 < 2) <error>{}</error> else <error>{}</error>
|
||||||
|
}
|
||||||
|
fun blockNoReturnIfUnitInOneBranch(): Int {
|
||||||
|
if (1 < 2) {
|
||||||
|
return 1
|
||||||
|
} else {
|
||||||
|
if (3 < 4) <error>{
|
||||||
|
}</error> else {
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) <error>{}</error> else <error>{}</error>
|
||||||
|
fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) <error>{}</error> else 2
|
||||||
|
|
||||||
val a = <error>return 1</error>
|
val a = <error>return 1</error>
|
||||||
|
|
||||||
class A() {
|
class A() {
|
||||||
@@ -148,18 +164,3 @@ fun f(): Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun f(): Int = if (1 < 2) 1 else returnNothing()
|
fun f(): Int = if (1 < 2) 1 else returnNothing()
|
||||||
|
|
||||||
fun blockNoReturnIfEmptyIf(): Int {
|
|
||||||
if (1 < 2) <error>{}</error> else <error>{}</error>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun blockNoReturnIfUnitInOneBranch(): Int {
|
|
||||||
if (1 < 2) {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
if (3 < 4) <error>{
|
|
||||||
}</error> else {
|
|
||||||
return 21
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user