diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java index d7abf9cf9cb..6ba97d48e48 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/PositioningStrategies.java @@ -39,31 +39,36 @@ public class PositioningStrategies { @NotNull @Override public List mark(@NotNull JetDeclaration declaration) { + return markElement(getElementToMark(declaration)); + } + + @Override + public boolean isValid(@NotNull JetDeclaration declaration) { + return !hasSyntaxErrors(getElementToMark(declaration)); + } + + private PsiElement getElementToMark(@NotNull JetDeclaration declaration) { JetTypeReference returnTypeRef = null; - ASTNode nameNode = null; + PsiElement nameIdentifierOrPlaceholder = null; if (declaration instanceof JetNamedFunction) { JetFunction function = (JetNamedFunction) declaration; returnTypeRef = function.getReturnTypeRef(); - nameNode = getNameNode(function); + nameIdentifierOrPlaceholder = function.getNameIdentifier(); } else if (declaration instanceof JetProperty) { JetProperty property = (JetProperty) declaration; returnTypeRef = property.getTypeRef(); - nameNode = getNameNode(property); + nameIdentifierOrPlaceholder = property.getNameIdentifier(); } else if (declaration instanceof JetPropertyAccessor) { JetPropertyAccessor accessor = (JetPropertyAccessor) declaration; returnTypeRef = accessor.getReturnTypeReference(); - nameNode = accessor.getNamePlaceholder().getNode(); + nameIdentifierOrPlaceholder = accessor.getNamePlaceholder(); } - if (returnTypeRef != null) return markElement(returnTypeRef); - if (nameNode != null) return markNode(nameNode); - return markElement(declaration); - } - private ASTNode getNameNode(JetNamedDeclaration function) { - PsiElement nameIdentifier = function.getNameIdentifier(); - return nameIdentifier == null ? null : nameIdentifier.getNode(); + if (returnTypeRef != null) return returnTypeRef; + if (nameIdentifierOrPlaceholder != null) return nameIdentifierOrPlaceholder; + return declaration; } }; diff --git a/compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.kt b/compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.kt new file mode 100644 index 00000000000..e7f2e42d1a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.kt @@ -0,0 +1,9 @@ +abstract class A { + abstract var x: Int; + abstract fun foo() : Int; +} + +abstract class C : A() { + override abstract var x: String = ? + override abstract fun foo(): String = ? +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index a46bee6ff6f..6f1d9769d87 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -469,6 +469,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/TypeInference.kt"); } + @TestMetadata("TypeMismatchOnOverrideWithSyntaxErrors.kt") + public void testTypeMismatchOnOverrideWithSyntaxErrors() throws Exception { + doTest("compiler/testData/diagnostics/tests/TypeMismatchOnOverrideWithSyntaxErrors.kt"); + } + @TestMetadata("UninitializedOrReassignedVariables.kt") public void testUninitializedOrReassignedVariables() throws Exception { doTest("compiler/testData/diagnostics/tests/UninitializedOrReassignedVariables.kt");