diff --git a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index 4788df99411..4f90be5696d 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -406,7 +406,9 @@ public class TopDownAnalyzer { List 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"); } } diff --git a/idea/testData/checker/FunctionReturnTypes.jet b/idea/testData/checker/FunctionReturnTypes.jet index c5d57b174be..43a607f9714 100644 --- a/idea/testData/checker/FunctionReturnTypes.jet +++ b/idea/testData/checker/FunctionReturnTypes.jet @@ -115,6 +115,22 @@ fun blockReturnValueTypeMatch() : Int { fun blockNoReturnIfValDeclaration(): Int { val x = 1 } +fun blockNoReturnIfEmptyIf(): Int { + if (1 < 2) {} else {} +} +fun blockNoReturnIfUnitInOneBranch(): Int { + if (1 < 2) { + return 1 + } else { + if (3 < 4) { + } else { + return 2 + } + } +} +fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) {} else {} +fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) {} else 2 + val a = return 1 class A() { @@ -148,18 +164,3 @@ fun f(): Int { } fun f(): Int = if (1 < 2) 1 else returnNothing() - -fun blockNoReturnIfEmptyIf(): Int { - if (1 < 2) {} else {} -} - -fun blockNoReturnIfUnitInOneBranch(): Int { - if (1 < 2) { - return 1 - } else { - if (3 < 4) { - } else { - return 21 - } - } -}