Fix exception on overridding var-property with a val constructor parameter
#KT-3810 Fixed
This commit is contained in:
@@ -281,7 +281,7 @@ public interface Errors {
|
|||||||
|
|
||||||
// Property-specific
|
// Property-specific
|
||||||
|
|
||||||
DiagnosticFactory2<JetProperty, PropertyDescriptor, PropertyDescriptor> VAR_OVERRIDDEN_BY_VAL =
|
DiagnosticFactory2<JetNamedDeclaration, PropertyDescriptor, PropertyDescriptor> VAR_OVERRIDDEN_BY_VAL =
|
||||||
DiagnosticFactory2.create(ERROR, VAL_OR_VAR_NODE);
|
DiagnosticFactory2.create(ERROR, VAL_OR_VAR_NODE);
|
||||||
|
|
||||||
DiagnosticFactory0<PsiElement> REDUNDANT_MODIFIER_IN_GETTER = DiagnosticFactory0.create(WARNING);
|
DiagnosticFactory0<PsiElement> REDUNDANT_MODIFIER_IN_GETTER = DiagnosticFactory0.create(WARNING);
|
||||||
|
|||||||
@@ -24,10 +24,7 @@ import org.jetbrains.kotlin.JetNodeTypes
|
|||||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
import org.jetbrains.kotlin.lexer.JetTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getCalleeHighlightingRange
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
|
||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
import kotlin.platform.platformStatic
|
import kotlin.platform.platformStatic
|
||||||
|
|
||||||
@@ -319,9 +316,13 @@ public object PositioningStrategies {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public val VAL_OR_VAR_NODE: PositioningStrategy<JetProperty> = object : PositioningStrategy<JetProperty>() {
|
public val VAL_OR_VAR_NODE: PositioningStrategy<JetNamedDeclaration> = object : PositioningStrategy<JetNamedDeclaration>() {
|
||||||
override fun mark(element: JetProperty): List<TextRange> {
|
override fun mark(element: JetNamedDeclaration): List<TextRange> {
|
||||||
return markElement(element.getValOrVarKeyword())
|
return when (element) {
|
||||||
|
is JetParameter -> markElement(element.valOrVarKeyword ?: element)
|
||||||
|
is JetProperty -> markElement(element.valOrVarKeyword)
|
||||||
|
else -> error("Declaration is neither a parameter nor a property: " + element.getElementTextWithContext())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -554,7 +554,7 @@ public class OverrideResolver {
|
|||||||
public void varOverriddenByVal(@NotNull CallableMemberDescriptor overridden) {
|
public void varOverriddenByVal(@NotNull CallableMemberDescriptor overridden) {
|
||||||
if (!kindMismatchError) {
|
if (!kindMismatchError) {
|
||||||
kindMismatchError = true;
|
kindMismatchError = true;
|
||||||
trace.report(VAR_OVERRIDDEN_BY_VAL.on((JetProperty) member, (PropertyDescriptor) declared, (PropertyDescriptor) overridden));
|
trace.report(VAR_OVERRIDDEN_BY_VAL.on(member, (PropertyDescriptor) declared, (PropertyDescriptor) overridden));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
interface A {
|
||||||
|
var foo: String
|
||||||
|
}
|
||||||
|
|
||||||
|
class B(override <!VAR_OVERRIDDEN_BY_VAL!>val<!> foo: String) : A
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
internal interface A {
|
||||||
|
internal abstract var foo: kotlin.String
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class B : A {
|
||||||
|
public constructor B(/*0*/ foo: kotlin.String)
|
||||||
|
internal open override /*1*/ val foo: kotlin.String
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -11220,6 +11220,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt3810.kt")
|
||||||
|
public void testKt3810() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt3810.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt385.109.441.kt")
|
@TestMetadata("kt385.109.441.kt")
|
||||||
public void testKt385_109_441() throws Exception {
|
public void testKt385_109_441() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt385.109.441.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt385.109.441.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user