Setup overridability rules for properties built on Java fields
- They overrides each other - They do not overrides Kotlin propeties and vice versa
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
// FILE: A.java
|
||||||
|
|
||||||
|
public class A {
|
||||||
|
public int size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: B.java
|
||||||
|
|
||||||
|
public class B implements A {
|
||||||
|
public int size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
B().size
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
|
|
||||||
|
public open class A {
|
||||||
|
public constructor A()
|
||||||
|
public final var size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class B : A {
|
||||||
|
public constructor B()
|
||||||
|
public final override /*1*/ var size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// FILE: B.java
|
||||||
|
|
||||||
|
abstract class B implements A {
|
||||||
|
public int size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
val size: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
class C : B() {
|
||||||
|
override val size: Int get() = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
C().<!OVERLOAD_RESOLUTION_AMBIGUITY!>size<!>
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
|
|
||||||
|
public interface A {
|
||||||
|
public abstract val size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
public/*package*/ abstract class B : A {
|
||||||
|
public/*package*/ constructor B()
|
||||||
|
public final var size: kotlin.Int
|
||||||
|
public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class C : B {
|
||||||
|
public constructor C()
|
||||||
|
public open override /*1*/ val size: kotlin.Int
|
||||||
|
public final override /*1*/ /*fake_override*/ var size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// FILE: B.java
|
||||||
|
|
||||||
|
abstract class B implements A {
|
||||||
|
private int size = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
interface A {
|
||||||
|
val size: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
class C : B() {
|
||||||
|
override val size: Int get() = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
C().size
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun foo(): kotlin.Unit
|
||||||
|
|
||||||
|
public interface A {
|
||||||
|
public abstract val size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
public/*package*/ abstract class B : A {
|
||||||
|
public/*package*/ constructor B()
|
||||||
|
private final var size: kotlin.Int
|
||||||
|
public abstract override /*1*/ /*fake_override*/ val size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class C : B {
|
||||||
|
public constructor C()
|
||||||
|
public open override /*1*/ val size: kotlin.Int
|
||||||
|
invisible_fake final override /*1*/ /*fake_override*/ var size: kotlin.Int
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -8694,6 +8694,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fieldOverridesField.kt")
|
||||||
|
public void testFieldOverridesField() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/fieldOverridesField.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fieldOverridesNothing.kt")
|
||||||
|
public void testFieldOverridesNothing() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/fieldOverridesNothing.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("GenericsInSupertypes.kt")
|
@TestMetadata("GenericsInSupertypes.kt")
|
||||||
public void testGenericsInSupertypes() throws Exception {
|
public void testGenericsInSupertypes() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/GenericsInSupertypes.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/GenericsInSupertypes.kt");
|
||||||
@@ -8856,6 +8868,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateFieldOverridesNothing.kt")
|
||||||
|
public void testPrivateFieldOverridesNothing() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/privateFieldOverridesNothing.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("privateNestedClassStaticMember.kt")
|
@TestMetadata("privateNestedClassStaticMember.kt")
|
||||||
public void testPrivateNestedClassStaticMember() throws Exception {
|
public void testPrivateNestedClassStaticMember() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.load.java.FieldOverridabilityCondition
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.load.java
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
||||||
|
|
||||||
|
class FieldOverridabilityCondition : ExternalOverridabilityCondition {
|
||||||
|
override fun isOverridable(superDescriptor: CallableDescriptor, subDescriptor: CallableDescriptor): Boolean {
|
||||||
|
if (subDescriptor !is PropertyDescriptor || superDescriptor !is PropertyDescriptor) return true
|
||||||
|
|
||||||
|
return subDescriptor.isJavaField == superDescriptor.isJavaField
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currently getter is null iff it's loaded from Java field
|
||||||
|
private val PropertyDescriptor.isJavaField: Boolean
|
||||||
|
get() = getter == null
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user