FIR: Fix overrides binding for Java inheritor
`overriddenMembers` contract requires original (non-enhanced) function See other usages Ignored tests have been working accidentally ^KT-43289 Open
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
// FILE: main.kt
|
||||
|
||||
fun foo(j: MyJavaClass) {
|
||||
j.bar()
|
||||
}
|
||||
|
||||
abstract class MyClass {
|
||||
open fun bar(y: String? = null) {}
|
||||
}
|
||||
|
||||
// FILE: MyJavaClass.java
|
||||
|
||||
public class MyJavaClass extends MyClass {
|
||||
public void bar(String y) {}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
FILE: main.kt
|
||||
public final fun foo(j: R|MyJavaClass|): R|kotlin/Unit| {
|
||||
R|<local>/j|.R|/MyJavaClass.bar|()
|
||||
}
|
||||
public abstract class MyClass : R|kotlin/Any| {
|
||||
public constructor(): R|MyClass| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public open fun bar(y: R|kotlin/String?| = Null(null)): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
Generated
+5
@@ -83,6 +83,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/defaultJavaImportHiding.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInheritedToJava.kt")
|
||||
public void testDefaultParametersInheritedToJava() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/defaultParametersInheritedToJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("definitelyNotNullAmbiguity.kt")
|
||||
public void testDefinitelyNotNullAmbiguity() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/definitelyNotNullAmbiguity.kt");
|
||||
|
||||
+5
@@ -83,6 +83,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/defaultJavaImportHiding.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInheritedToJava.kt")
|
||||
public void testDefaultParametersInheritedToJava() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/defaultParametersInheritedToJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("definitelyNotNullAmbiguity.kt")
|
||||
public void testDefinitelyNotNullAmbiguity() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/definitelyNotNullAmbiguity.kt");
|
||||
|
||||
+5
@@ -83,6 +83,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/defaultJavaImportHiding.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInheritedToJava.kt")
|
||||
public void testDefaultParametersInheritedToJava() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/defaultParametersInheritedToJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("definitelyNotNullAmbiguity.kt")
|
||||
public void testDefinitelyNotNullAmbiguity() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/definitelyNotNullAmbiguity.kt");
|
||||
|
||||
+12
-7
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.java.enhancement.FirSignatureEnhancement
|
||||
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
|
||||
@@ -46,11 +47,11 @@ class JavaClassMembersEnhancementScope(
|
||||
override fun processPropertiesByName(name: Name, processor: (FirVariableSymbol<*>) -> Unit) {
|
||||
useSiteMemberScope.processPropertiesByName(name) process@{ original ->
|
||||
val enhancedPropertySymbol = signatureEnhancement.enhancedProperty(original, name)
|
||||
|
||||
if (enhancedPropertySymbol is FirPropertySymbol) {
|
||||
val originalFir = original.fir
|
||||
if (originalFir is FirProperty && enhancedPropertySymbol is FirPropertySymbol) {
|
||||
val enhancedProperty = enhancedPropertySymbol.fir
|
||||
overriddenProperties[enhancedPropertySymbol] =
|
||||
enhancedProperty
|
||||
originalFir
|
||||
.overriddenMembers(enhancedProperty.name)
|
||||
.mapNotNull { it.symbol as? FirPropertySymbol }
|
||||
}
|
||||
@@ -141,11 +142,15 @@ class JavaClassMembersEnhancementScope(
|
||||
val enhancedFunction = (symbol.fir as? FirSimpleFunction)?.changeSignatureIfErasedValueParameter()
|
||||
val enhancedFunctionSymbol = enhancedFunction?.symbol ?: symbol
|
||||
|
||||
val originalFunction = original.fir as? FirSimpleFunction
|
||||
|
||||
overriddenFunctions[enhancedFunctionSymbol] =
|
||||
enhancedFunction
|
||||
?.overriddenMembers(enhancedFunction.name)
|
||||
?.mapNotNull { it.symbol as? FirFunctionSymbol<*> }
|
||||
.orEmpty()
|
||||
if (enhancedFunction != null && originalFunction != null)
|
||||
originalFunction
|
||||
.overriddenMembers(enhancedFunction.name)
|
||||
.mapNotNull { it.symbol as? FirFunctionSymbol<*> }
|
||||
else
|
||||
emptyList()
|
||||
|
||||
processor(enhancedFunctionSymbol)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
// FILE: J.java
|
||||
|
||||
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// FILE: javaCollectionWithRemovePrimitiveInt.kt
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
// FULL_JDK
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// !JVM_DEFAULT_MODE: disable
|
||||
// JVM_TARGET: 1.8
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// FILE: JBase.java
|
||||
|
||||
public interface JBase extends Base {
|
||||
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// FILE: A.kt
|
||||
@@ -21,4 +20,4 @@ fun box(): String {
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// FILE: AbstractSpecializedMap.java
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
public abstract class AbstractSpecializedMap implements java.util.Map<Integer, Double> {
|
||||
public abstract double put(int x, double y);
|
||||
public abstract double remove(int k);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// FILE: A.java
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
import java.util.HashMap;
|
||||
|
||||
public class A extends HashMap<Integer, Double> {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// FILE: CharBuffer.java
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
public abstract class CharBuffer implements CharSequence {
|
||||
public final int length() {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
abstract class A1<Q> : MutableCollection<Q> {
|
||||
override fun contains(o: Q): Boolean {
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
Vendored
-57
@@ -1,57 +0,0 @@
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class A {
|
||||
public void foo(@DefaultNull Integer i) {}
|
||||
|
||||
public void bar(@DefaultNull Integer a) {}
|
||||
|
||||
public void bam(@DefaultNull Integer a) {}
|
||||
|
||||
public void baz(@DefaultValue("42") Integer a) {}
|
||||
}
|
||||
|
||||
// FILE: AInt.java
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public interface AInt {
|
||||
public void foo(@DefaultValue("42") Integer i) {}
|
||||
public void bar(@DefaultNull Integer a) {}
|
||||
}
|
||||
|
||||
// FILE: B.java
|
||||
import kotlin.annotations.jvm.internal.*;
|
||||
|
||||
public class B extends A {
|
||||
public void foo(Integer i) {}
|
||||
|
||||
public void bar(@DefaultValue("42") Integer a) {}
|
||||
|
||||
public void bam(@DefaultNull @DefaultValue("42") Integer a) {}
|
||||
}
|
||||
|
||||
// FILE: C.java
|
||||
public class C extends A implements AInt {
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(b: B, c: C) {
|
||||
b.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
b.foo(5)
|
||||
b.bar()
|
||||
b.bar(5)
|
||||
b.bam()
|
||||
b.bam(5)
|
||||
|
||||
c.foo()
|
||||
c.foo(5)
|
||||
c.bar()
|
||||
c.bar(5)
|
||||
c.bam()
|
||||
c.bam(5)
|
||||
c.baz()
|
||||
c.baz(42)
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: A.java
|
||||
// ANDROID_ANNOTATIONS
|
||||
|
||||
|
||||
+3
-3
@@ -87,14 +87,14 @@ fun main() {
|
||||
d.<!INAPPLICABLE_CANDIDATE!>first<!>()
|
||||
bd.<!INAPPLICABLE_CANDIDATE!>first<!>()
|
||||
|
||||
e.<!INAPPLICABLE_CANDIDATE!>first<!>()
|
||||
e.first()
|
||||
|
||||
val g = G()
|
||||
g.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
g.foo()
|
||||
g.foo("ok")
|
||||
|
||||
val m = M()
|
||||
m.<!INAPPLICABLE_CANDIDATE!>foo<!>()
|
||||
m.foo()
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user