NPE on unfinished function declaration fixed

This commit is contained in:
svtk
2011-09-07 13:22:47 +04:00
parent 2f4377d7c0
commit d9137f18cc
2 changed files with 24 additions and 20 deletions
@@ -406,7 +406,9 @@ public class TopDownAnalyzer {
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
for (JetAnnotationEntry annotationEntry : annotationEntries) {
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) {
PsiElement nameIdentifier = function.getNameIdentifier();
if (containingDescriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) containingDescriptor;
if (functionDescriptor.getModifiers().isAbstract() && !classDescriptor.isAbstract()) {
trace.getErrorHandler().genericError(function.getModifierList().getModifierNode(JetTokens.ABSTRACT_KEYWORD),
"Abstract method " + function.getName() + " in non-abstract class " + classDescriptor.getName());
}
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract()) {
trace.getErrorHandler().genericError(function.getNameIdentifier().getNode(), "Method without body must be abstract");
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract() && nameIdentifier != null) {
trace.getErrorHandler().genericError(nameIdentifier.getNode(), "Method " + function.getName() + " without body must be abstract");
}
return;
}
@@ -979,8 +982,8 @@ public class TopDownAnalyzer {
trace.getErrorHandler().genericError(function.getModifierList().getModifierNode(JetTokens.ABSTRACT_KEYWORD),
"Global function " + function.getName() + " can not be abstract");
}
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract()) {
trace.getErrorHandler().genericError(function.getNameIdentifier().getNode(), "Global function must have body");
if (function.getBodyExpression() == null && !functionDescriptor.getModifiers().isAbstract() && nameIdentifier != null) {
trace.getErrorHandler().genericError(nameIdentifier.getNode(), "Global function " + function.getName() + " must have body");
}
}
+16 -15
View File
@@ -115,6 +115,22 @@ fun blockReturnValueTypeMatch() : Int {
fun blockNoReturnIfValDeclaration(): Int {
<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>
class A() {
@@ -148,18 +164,3 @@ fun f(): Int {
}
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
}
}
}