KT-3378 "Type mismatch on override" not present when the initializer is syntactically incorrect

#KT-3378 Fixed
This commit is contained in:
Wojciech Lopata
2013-03-05 18:53:06 +01:00
committed by Evgeny Gerashchenko
parent 09c3edcbc7
commit 75528e0a4a
3 changed files with 30 additions and 11 deletions
@@ -39,31 +39,36 @@ public class PositioningStrategies {
@NotNull
@Override
public List<TextRange> 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;
}
};
@@ -0,0 +1,9 @@
abstract class A {
abstract var x: Int;
abstract fun foo() : Int;
}
abstract class C : A() {
override abstract var x: <!PROPERTY_TYPE_MISMATCH_ON_OVERRIDE!>String<!> =<!SYNTAX!><!> <!SYNTAX!>?<!>
override abstract fun foo(): <!RETURN_TYPE_MISMATCH_ON_OVERRIDE!>String<!> =<!SYNTAX!><!> <!SYNTAX!>?<!>
}
@@ -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");