KT-3378 "Type mismatch on override" not present when the initializer is syntactically incorrect
#KT-3378 Fixed
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
09c3edcbc7
commit
75528e0a4a
+16
-11
@@ -39,31 +39,36 @@ public class PositioningStrategies {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<TextRange> mark(@NotNull JetDeclaration declaration) {
|
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;
|
JetTypeReference returnTypeRef = null;
|
||||||
ASTNode nameNode = null;
|
PsiElement nameIdentifierOrPlaceholder = null;
|
||||||
if (declaration instanceof JetNamedFunction) {
|
if (declaration instanceof JetNamedFunction) {
|
||||||
JetFunction function = (JetNamedFunction) declaration;
|
JetFunction function = (JetNamedFunction) declaration;
|
||||||
returnTypeRef = function.getReturnTypeRef();
|
returnTypeRef = function.getReturnTypeRef();
|
||||||
nameNode = getNameNode(function);
|
nameIdentifierOrPlaceholder = function.getNameIdentifier();
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetProperty) {
|
else if (declaration instanceof JetProperty) {
|
||||||
JetProperty property = (JetProperty) declaration;
|
JetProperty property = (JetProperty) declaration;
|
||||||
returnTypeRef = property.getTypeRef();
|
returnTypeRef = property.getTypeRef();
|
||||||
nameNode = getNameNode(property);
|
nameIdentifierOrPlaceholder = property.getNameIdentifier();
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetPropertyAccessor) {
|
else if (declaration instanceof JetPropertyAccessor) {
|
||||||
JetPropertyAccessor accessor = (JetPropertyAccessor) declaration;
|
JetPropertyAccessor accessor = (JetPropertyAccessor) declaration;
|
||||||
returnTypeRef = accessor.getReturnTypeReference();
|
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) {
|
if (returnTypeRef != null) return returnTypeRef;
|
||||||
PsiElement nameIdentifier = function.getNameIdentifier();
|
if (nameIdentifierOrPlaceholder != null) return nameIdentifierOrPlaceholder;
|
||||||
return nameIdentifier == null ? null : nameIdentifier.getNode();
|
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");
|
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")
|
@TestMetadata("UninitializedOrReassignedVariables.kt")
|
||||||
public void testUninitializedOrReassignedVariables() throws Exception {
|
public void testUninitializedOrReassignedVariables() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/UninitializedOrReassignedVariables.kt");
|
doTest("compiler/testData/diagnostics/tests/UninitializedOrReassignedVariables.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user