[FIR] Create special hidden override for Java signature clash due to rename
This fixes CharBuffer.get resolving to CharBuffer.charAt #KT-61282 Fixed
This commit is contained in:
committed by
Space Team
parent
528a2d3c62
commit
865b8a4175
+6
@@ -21682,6 +21682,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
public void testSizeFromKotlinOverriddenInJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -51721,6 +51721,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -21682,6 +21682,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
public void testSizeFromKotlinOverriddenInJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -51721,6 +51721,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -21676,6 +21676,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
public void testSizeFromKotlinOverriddenInJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -21682,6 +21682,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
public void testSizeFromKotlinOverriddenInJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+2
@@ -58,6 +58,8 @@ private fun FirBasedSymbol<*>.isCollectable(): Boolean {
|
||||
if (typeParameterSymbols.any { it.toConeType().hasError() }) return false
|
||||
if (receiverParameter?.typeRef?.coneType?.hasError() == true) return false
|
||||
if (this is FirFunctionSymbol<*> && valueParameterSymbols.any { it.resolvedReturnType.hasError() }) return false
|
||||
@OptIn(SymbolInternals::class)
|
||||
if (fir.isHiddenToOvercomeSignatureClash == true) return false
|
||||
}
|
||||
|
||||
return when (this) {
|
||||
|
||||
@@ -715,7 +715,7 @@ fun FirDeclaration?.computeIrOrigin(
|
||||
|
||||
this is FirCallableDeclaration -> when {
|
||||
fakeOverrideOwnerLookupTag != null && fakeOverrideOwnerLookupTag != containingClassLookupTag() -> IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
symbol.fir.isIntersectionOverride || symbol.fir.isSubstitutionOverride -> IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
isSubstitutionOrIntersectionOverride || isHiddenToOvercomeSignatureClash == true -> IrDeclarationOrigin.FAKE_OVERRIDE
|
||||
parentOrigin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB && symbol.isJavaOrEnhancement -> {
|
||||
IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||
}
|
||||
|
||||
+3
-1
@@ -91,5 +91,7 @@ class Fir2IrLazyDeclarationsGenerator(val components: Fir2IrComponents) : Fir2Ir
|
||||
|
||||
internal fun FirCallableDeclaration.isFakeOverride(firContainingClass: FirRegularClass?): Boolean {
|
||||
val declaration = unwrapUseSiteSubstitutionOverrides()
|
||||
return declaration.isSubstitutionOrIntersectionOverride || firContainingClass?.symbol?.toLookupTag() != declaration.containingClassLookupTag()
|
||||
return declaration.isSubstitutionOrIntersectionOverride ||
|
||||
firContainingClass?.symbol?.toLookupTag() != declaration.containingClassLookupTag() ||
|
||||
declaration.isHiddenToOvercomeSignatureClash == true
|
||||
}
|
||||
|
||||
+6
@@ -51140,6 +51140,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -51140,6 +51140,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -51140,6 +51140,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+107
-37
@@ -407,12 +407,8 @@ class JavaClassUseSiteMemberScope(
|
||||
val explicitlyDeclaredFunctionWithNaturalName = explicitlyDeclaredFunctionsWithNaturalName.firstOrNull {
|
||||
overrideCheckerForSpecialFunctions.isOverriddenFunction(it, someSymbolWithNaturalNameFromSuperType)
|
||||
}
|
||||
val jvmName = resultOfIntersectionWithNaturalName.overriddenMembers.firstNotNullOfOrNull {
|
||||
it.member.getJvmMethodNameIfSpecial(it.baseScope, session)
|
||||
}
|
||||
if (jvmName != null) {
|
||||
processOverridesForFunctionsWithDifferentJvmName(
|
||||
jvmName,
|
||||
|
||||
if (processOverridesForFunctionsWithDifferentJvmName(
|
||||
someSymbolWithNaturalNameFromSuperType,
|
||||
explicitlyDeclaredFunctionWithNaturalName,
|
||||
requestedName,
|
||||
@@ -420,6 +416,7 @@ class JavaClassUseSiteMemberScope(
|
||||
destination,
|
||||
resultsOfIntersectionToSaveInCache
|
||||
)
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -529,16 +526,18 @@ class JavaClassUseSiteMemberScope(
|
||||
}
|
||||
|
||||
private fun processOverridesForFunctionsWithDifferentJvmName(
|
||||
jvmName: Name,
|
||||
// The JVM name of the function, e.g., byteValue or charAt
|
||||
someSymbolWithNaturalNameFromSuperType: FirNamedFunctionSymbol,
|
||||
explicitlyDeclaredFunctionWithNaturalName: FirNamedFunctionSymbol?,
|
||||
// The Kotlin name of the function, e.g., toByte or get
|
||||
naturalName: Name,
|
||||
resultOfIntersectionWithNaturalName: ResultOfIntersection<FirNamedFunctionSymbol>,
|
||||
destination: MutableCollection<FirNamedFunctionSymbol>,
|
||||
resultsOfIntersectionToSaveInCache: MutableList<ResultOfIntersection<FirNamedFunctionSymbol>>
|
||||
) {
|
||||
): Boolean {
|
||||
/*
|
||||
* name: toByte
|
||||
* naturalName: toByte
|
||||
* jvmName: byteValue
|
||||
*
|
||||
* 1. find declared byteValue (a)
|
||||
* 2. find toByte in supertypes (b)
|
||||
@@ -552,7 +551,20 @@ class JavaClassUseSiteMemberScope(
|
||||
* 7.1 create renamed copies of (c): (c')
|
||||
* 7.2 save direct overrides
|
||||
*/
|
||||
val overriddenMembers = resultOfIntersectionWithNaturalName.overriddenMembers
|
||||
|
||||
val jvmName = resultOfIntersectionWithNaturalName.overriddenMembers.firstNotNullOfOrNull {
|
||||
it.member.getJvmMethodNameIfSpecial(it.baseScope, session)
|
||||
} ?: return false
|
||||
|
||||
|
||||
// Among the overridden members, some can be regular members and some can be renamed from jvmName to naturalName.
|
||||
// If we have the CharBuffer situation, the visible member will override the regular ones and the hidden member will
|
||||
// override the renamed ones (if they exist).
|
||||
val (overriddenByJvmName, overriddenByNaturalName) =
|
||||
resultOfIntersectionWithNaturalName.overriddenMembers.partition {
|
||||
it.member.getJvmMethodNameIfSpecial(it.baseScope, session) == jvmName
|
||||
}
|
||||
|
||||
val explicitlyDeclaredFunctionWithBuiltinJvmName = declaredMemberScope.getFunctions(jvmName).firstOrNull {
|
||||
overrideChecker.isOverriddenFunction(it, someSymbolWithNaturalNameFromSuperType)
|
||||
}
|
||||
@@ -563,52 +575,110 @@ class JavaClassUseSiteMemberScope(
|
||||
)
|
||||
}
|
||||
|
||||
val declaredFunction = explicitlyDeclaredFunctionWithNaturalName ?: explicitlyDeclaredFunctionWithBuiltinJvmName?.let {
|
||||
val original = it.fir as FirJavaMethod
|
||||
buildJavaMethodCopy(original) {
|
||||
name = naturalName
|
||||
symbol = FirNamedFunctionSymbol(it.callableId.copy(callableName = naturalName))
|
||||
status = original.status.copy(isOperator = true)
|
||||
fun createCopyWithNaturalName(
|
||||
originalSymbol: FirNamedFunctionSymbol,
|
||||
isHidden: Boolean = false,
|
||||
origin: FirDeclarationOrigin? = null,
|
||||
): FirNamedFunctionSymbol {
|
||||
val original = originalSymbol.fir
|
||||
val newSymbol = FirNamedFunctionSymbol(originalSymbol.callableId.copy(callableName = naturalName))
|
||||
|
||||
// If original is declared, it's a FirJavaMethod.
|
||||
// If it's inherited, it's a (possibly enhanced) FirSimpleMethod.
|
||||
return if (original is FirJavaMethod) {
|
||||
buildJavaMethodCopy(original) {
|
||||
name = naturalName
|
||||
symbol = newSymbol
|
||||
dispatchReceiverType = klass.defaultType()
|
||||
|
||||
// Technically, it should only be an operator if it matches an operator naming convention,
|
||||
// but always setting it doesn't seem to hurt.
|
||||
status = original.status.copy(isOperator = true)
|
||||
}
|
||||
} else {
|
||||
buildSimpleFunctionCopy(original) {
|
||||
name = naturalName
|
||||
symbol = newSymbol
|
||||
dispatchReceiverType = klass.defaultType()
|
||||
origin?.let { this.origin = it }
|
||||
}
|
||||
}.apply {
|
||||
initialSignatureAttr = original
|
||||
if (isHidden) {
|
||||
isHiddenToOvercomeSignatureClash = true
|
||||
}
|
||||
}.symbol
|
||||
}
|
||||
|
||||
val renamedFunctionsFromSupertypes = functionsFromSupertypesWithBuiltinJvmName?.overriddenMembers?.map {
|
||||
val renamedFunction = buildSimpleFunctionCopy(it.member.fir) {
|
||||
name = naturalName
|
||||
symbol = FirNamedFunctionSymbol(it.member.callableId.copy(callableName = naturalName))
|
||||
origin = FirDeclarationOrigin.RenamedForOverride
|
||||
}.apply {
|
||||
initialSignatureAttr = it.member.fir
|
||||
}
|
||||
it.baseScope to listOf(renamedFunction.symbol)
|
||||
val renamedFunction = createCopyWithNaturalName(it.member, origin = FirDeclarationOrigin.RenamedForOverride)
|
||||
it.baseScope to listOf(renamedFunction)
|
||||
}
|
||||
|
||||
val resultsOfIntersection = when (renamedFunctionsFromSupertypes) {
|
||||
null -> listOf(resultOfIntersectionWithNaturalName)
|
||||
val resultsOfIntersectionOfRenamed = when {
|
||||
renamedFunctionsFromSupertypes == null && overriddenByNaturalName.isEmpty() -> listOf(resultOfIntersectionWithNaturalName)
|
||||
else -> {
|
||||
val membersByScope = buildList {
|
||||
overriddenMembers.mapTo(this) { it.baseScope to listOf(it.member) }
|
||||
addAll(renamedFunctionsFromSupertypes)
|
||||
overriddenByJvmName.mapTo(this) { it.baseScope to listOf(it.member) }
|
||||
addAll(renamedFunctionsFromSupertypes.orEmpty())
|
||||
}
|
||||
supertypeScopeContext.convertGroupedCallablesToIntersectionResults(membersByScope)
|
||||
}
|
||||
}
|
||||
|
||||
if (declaredFunction != null) {
|
||||
destination += declaredFunction
|
||||
directOverriddenFunctions[declaredFunction] = resultsOfIntersection
|
||||
for (resultOfIntersection in resultsOfIntersection) {
|
||||
for (overriddenMember in resultOfIntersection.overriddenMembers) {
|
||||
overrideByBase[overriddenMember.member] = declaredFunction
|
||||
val explicitlyDeclaredOrInheritedFunctionWithBuiltinJvmName =
|
||||
// we know overriddenByJvmName is non-empty, otherwise we would have early returned in the beginning.
|
||||
explicitlyDeclaredFunctionWithBuiltinJvmName ?: overriddenByJvmName.first().member
|
||||
|
||||
if (explicitlyDeclaredFunctionWithNaturalName != null || overriddenByNaturalName.isNotEmpty()) {
|
||||
// The CharBuffer situation: both get(Int):Char and charAt(Int):Char are declared or inherited.
|
||||
|
||||
// CharBuffer.charAt is renamed to get, becomes hidden and overrides kotlin.CharSequence.charAt.
|
||||
val hiddenRenamedFunction = createCopyWithNaturalName(explicitlyDeclaredOrInheritedFunctionWithBuiltinJvmName, isHidden = true)
|
||||
destination += hiddenRenamedFunction
|
||||
setOverrides(hiddenRenamedFunction, resultsOfIntersectionOfRenamed)
|
||||
|
||||
val resultOfIntersectionOfNaturalName = supertypeScopeContext.convertGroupedCallablesToIntersectionResults(
|
||||
overriddenByNaturalName.map { it.baseScope to listOf(it.member) }
|
||||
)
|
||||
|
||||
if (explicitlyDeclaredFunctionWithNaturalName != null) {
|
||||
// CharBuffer.get is already in destination, but we need to update its overridden declarations.
|
||||
// It mustn't override kotlin.CharSequence.charAt, but it can override different declarations with the same signature.
|
||||
// See compiler/testData/diagnostics/tests/j+k/collectionOverrides/charBuffer.kt
|
||||
setOverrides(explicitlyDeclaredFunctionWithNaturalName, resultOfIntersectionOfNaturalName)
|
||||
} else {
|
||||
// CharBuffer.get is inherited (possibly a real intersection).
|
||||
// Add it to destination and set overridden declarations.
|
||||
val intersectionOfNaturalName = resultOfIntersectionOfNaturalName.single()
|
||||
destination += intersectionOfNaturalName.chosenSymbol
|
||||
if (intersectionOfNaturalName is ResultOfIntersection.NonTrivial) {
|
||||
setOverrides(intersectionOfNaturalName.chosenSymbol, resultOfIntersectionOfNaturalName)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (resultOfIntersection in resultsOfIntersection) {
|
||||
destination += resultOfIntersection.chosenSymbol
|
||||
val declaredFunction = explicitlyDeclaredFunctionWithBuiltinJvmName?.let { createCopyWithNaturalName(it) }
|
||||
|
||||
if (declaredFunction != null) {
|
||||
destination += declaredFunction
|
||||
setOverrides(declaredFunction, resultsOfIntersectionOfRenamed)
|
||||
} else {
|
||||
for (resultOfIntersection in resultsOfIntersectionOfRenamed) {
|
||||
destination += resultOfIntersection.chosenSymbol
|
||||
}
|
||||
resultsOfIntersectionToSaveInCache += resultsOfIntersectionOfRenamed
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun setOverrides(override: FirNamedFunctionSymbol, overridden: List<ResultOfIntersection<FirNamedFunctionSymbol>>) {
|
||||
directOverriddenFunctions[override] = overridden
|
||||
for (resultOfIntersection in overridden) {
|
||||
for (overriddenMember in resultOfIntersection.overriddenMembers) {
|
||||
overrideByBase[overriddenMember.member] = override
|
||||
}
|
||||
resultsOfIntersectionToSaveInCache += resultsOfIntersection
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -322,3 +322,9 @@ private object IsHiddenEverywhereBesideSuperCalls : FirDeclarationDataKey()
|
||||
var FirCallableDeclaration.isHiddenEverywhereBesideSuperCalls: Boolean? by FirDeclarationDataRegistry.data(
|
||||
IsHiddenEverywhereBesideSuperCalls
|
||||
)
|
||||
|
||||
private object IsHiddenToOvercomeSignatureClash : FirDeclarationDataKey()
|
||||
|
||||
var FirCallableDeclaration.isHiddenToOvercomeSignatureClash: Boolean? by FirDeclarationDataRegistry.data(
|
||||
IsHiddenToOvercomeSignatureClash
|
||||
)
|
||||
|
||||
@@ -716,15 +716,15 @@ internal object CheckHiddenDeclaration : ResolutionStage() {
|
||||
callInfo: CallInfo,
|
||||
candidate: Candidate,
|
||||
): Boolean {
|
||||
if (callInfo.callSite.isSuperCall()) return false
|
||||
val isSuperCall = callInfo.callSite.isSuperCall()
|
||||
if (symbol.fir.dispatchReceiverType == null || symbol !is FirNamedFunctionSymbol) return false
|
||||
if (symbol.fir.isHiddenEverywhereBesideSuperCalls == true) return true
|
||||
if (symbol.isHidden(isSuperCall)) return true
|
||||
|
||||
val scope = candidate.originScope as? FirTypeScope ?: return false
|
||||
|
||||
var result = false
|
||||
scope.processOverriddenFunctions(symbol) {
|
||||
if (it.fir.isHiddenEverywhereBesideSuperCalls == true) {
|
||||
if (it.isHidden(isSuperCall)) {
|
||||
result = true
|
||||
ProcessorAction.STOP
|
||||
} else {
|
||||
@@ -737,6 +737,11 @@ internal object CheckHiddenDeclaration : ResolutionStage() {
|
||||
|
||||
private fun FirElement.isSuperCall(): Boolean =
|
||||
this is FirQualifiedAccessExpression && explicitReceiver?.calleeReference is FirSuperReference
|
||||
|
||||
private fun FirCallableSymbol<*>.isHidden(isSuperCall: Boolean): Boolean {
|
||||
val fir = fir
|
||||
return !isSuperCall && fir.isHiddenEverywhereBesideSuperCalls == true || fir.isHiddenToOvercomeSignatureClash == true
|
||||
}
|
||||
}
|
||||
|
||||
private val DYNAMIC_EXTENSION_ANNOTATION_CLASS_ID: ClassId = ClassId.topLevel(DYNAMIC_EXTENSION_FQ_NAME)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
// Ignore reason: KT-61282
|
||||
// FULL_JDK
|
||||
|
||||
import java.nio.CharBuffer
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_K2: JVM_IR
|
||||
// Ignore reason: KT-61282
|
||||
// MODULE: lib
|
||||
// FILE: CharBuffer.java
|
||||
|
||||
@@ -34,6 +32,7 @@ public abstract class CharBuffer implements CharSequence {
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: 1.kt
|
||||
abstract class KCB : CharBuffer()
|
||||
|
||||
fun box(): String {
|
||||
val cb: CharBuffer = CharBuffer.impl()
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_K1: ANY
|
||||
// ^KT-63431 CharBufferXAllInherited.create().get(0) is resolved incorrectly in K1
|
||||
|
||||
// FILE: X.java
|
||||
public interface X {
|
||||
char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBuffer.java
|
||||
public abstract class CharBuffer implements CharSequence {
|
||||
public static CharBuffer create() {
|
||||
return new CharBuffer() {
|
||||
@Override public char charAt(int index) { return 'c'; }
|
||||
@Override public char get(int index) { return 'g'; }
|
||||
@Override public CharSequence subSequence(int start, int end) { return null; }
|
||||
@Override public int length() { return 0; }
|
||||
};
|
||||
}
|
||||
public abstract char charAt(int index);
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferX.java
|
||||
public abstract class CharBufferX implements CharSequence, X {
|
||||
public static CharBufferX create() {
|
||||
return new CharBufferX() {
|
||||
@Override public char charAt(int index) { return 'c'; }
|
||||
@Override public char get(int index) { return 'g'; }
|
||||
@Override public CharSequence subSequence(int start, int end) { return null; }
|
||||
@Override public int length() { return 0; }
|
||||
};
|
||||
}
|
||||
public abstract char charAt(int index);
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: NonCharSequenceBuffer.java
|
||||
public abstract class NonCharSequenceBuffer implements X {
|
||||
public static NonCharSequenceBuffer create() {
|
||||
return new NonCharSequenceBuffer() {
|
||||
@Override public char charAt(int index) { return 'c'; }
|
||||
@Override public char get(int index) { return 'g'; }
|
||||
};
|
||||
}
|
||||
public abstract char charAt(int index);
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferCharAtInherited.java
|
||||
public abstract class CharBufferCharAtInherited implements CharSequence {
|
||||
public static CharBufferCharAtInherited create() {
|
||||
return new CharBufferCharAtInherited() {
|
||||
@Override public char charAt(int index) { return 'c'; }
|
||||
@Override public char get(int index) { return 'g'; }
|
||||
@Override public CharSequence subSequence(int start, int end) { return null; }
|
||||
@Override public int length() { return 0; }
|
||||
};
|
||||
}
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferXAllInherited.java
|
||||
public abstract class CharBufferXAllInherited implements CharSequence, X {
|
||||
public static CharBufferXAllInherited create() {
|
||||
return new CharBufferXAllInherited() {
|
||||
@Override public char charAt(int index) { return 'c'; }
|
||||
@Override public char get(int index) { return 'g'; }
|
||||
@Override public CharSequence subSequence(int start, int end) { return null; }
|
||||
@Override public int length() { return 0; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: Y.java
|
||||
public abstract class Y {
|
||||
protected abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferXYAllInherited.java
|
||||
public abstract class CharBufferXYAllInherited extends Y implements CharSequence, X {
|
||||
public static CharBufferXYAllInherited create() {
|
||||
return new CharBufferXYAllInherited() {
|
||||
@Override public char charAt(int index) { return 'c'; }
|
||||
@Override public char get(int index) { return 'g'; }
|
||||
@Override public CharSequence subSequence(int start, int end) { return null; }
|
||||
@Override public int length() { return 0; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: CharAt.java
|
||||
public interface CharAt {
|
||||
char charAt(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferXYCharAt.java
|
||||
public abstract class CharBufferXYCharAt extends Y implements CharSequence, X, CharAt {
|
||||
public static CharBufferXYCharAt create() {
|
||||
return new CharBufferXYCharAt() {
|
||||
@Override public char charAt(int index) { return 'c'; }
|
||||
@Override public char get(int index) { return 'g'; }
|
||||
@Override public CharSequence subSequence(int start, int end) { return null; }
|
||||
@Override public int length() { return 0; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: box.kt
|
||||
|
||||
fun box(): String {
|
||||
if (CharBuffer.create().get(0) != 'g') return "FAIL 1"
|
||||
if ((CharBuffer.create() as CharSequence).get(0) != 'c') return "FAIL 2"
|
||||
|
||||
if (CharBufferX.create().get(0) != 'g') return "FAIL 3"
|
||||
if ((CharBufferX.create() as CharSequence).get(0) != 'c') return "FAIL 4"
|
||||
if ((CharBufferX.create() as X).get(0) != 'g') return "FAIL 5"
|
||||
|
||||
if (NonCharSequenceBuffer.create().charAt(0) != 'c') return "FAIL 6"
|
||||
if (NonCharSequenceBuffer.create().get(0) != 'g') return "FAIL 7"
|
||||
if ((NonCharSequenceBuffer.create() as X).get(0) != 'g') return "FAIL 8"
|
||||
|
||||
if (CharBufferCharAtInherited.create().get(0) != 'g') return "FAIL 9"
|
||||
if ((CharBufferCharAtInherited.create() as CharSequence).get(0) != 'c') return "FAIL 10"
|
||||
|
||||
if (CharBufferXAllInherited.create().get(0) != 'g') return "FAIL 11"
|
||||
if ((CharBufferXAllInherited.create() as CharSequence).get(0) != 'c') return "FAIL 12"
|
||||
if ((CharBufferXAllInherited.create() as X).get(0) != 'g') return "FAIL 13"
|
||||
|
||||
if (CharBufferXYAllInherited.create().get(0) != 'g') return "FAIL 14"
|
||||
if ((CharBufferXYAllInherited.create() as CharSequence).get(0) != 'c') return "FAIL 15"
|
||||
if ((CharBufferXYAllInherited.create() as X).get(0) != 'g') return "FAIL 16"
|
||||
if ((CharBufferXYAllInherited.create() as Y).get(0) != 'g') return "FAIL 17"
|
||||
|
||||
if (CharBufferXYCharAt.create().get(0) != 'g') return "FAIL 18"
|
||||
if ((CharBufferXYCharAt.create() as CharSequence).get(0) != 'c') return "FAIL 19"
|
||||
if ((CharBufferXYCharAt.create() as X).get(0) != 'g') return "FAIL 20"
|
||||
if ((CharBufferXYCharAt.create() as Y).get(0) != 'g') return "FAIL 21"
|
||||
if ((CharBufferXYCharAt.create() as CharAt).charAt(0) != 'c') return "FAIL 22"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
// FIR_IDENTICAL
|
||||
// SCOPE_DUMP: CharBuffer:get;charAt, CharBufferX:get;charAt, NonCharSequenceBuffer:get;charAt, NonCharBuffer:get;charAt, CharBufferXAllInherited:get;charAt, CharBufferXYAllInherited:get;charAt, CharBufferXYCharAt:get;charAt
|
||||
|
||||
// FILE: X.java
|
||||
public interface X {
|
||||
char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBuffer.java
|
||||
public abstract class CharBuffer implements CharSequence {
|
||||
// Should override 'kotlin.CharSequence.get'
|
||||
public final char charAt(int index) {
|
||||
return get(position() + checkIndex(index, 1));
|
||||
}
|
||||
|
||||
// The key problem here is that `get` has the same signature as kotlin.CharSequence.get but completely different semantics
|
||||
// Should override nothing
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferX.java
|
||||
public abstract class CharBufferX implements CharSequence, X {
|
||||
// Should override 'kotlin.CharSequence.get'
|
||||
public final char charAt(int index) {
|
||||
return get(position() + checkIndex(index, 1));
|
||||
}
|
||||
|
||||
// Should override X.get
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: NonCharSequenceBuffer.java
|
||||
public abstract class NonCharSequenceBuffer implements X {
|
||||
// Should override nothing and be available as 'charAt', not as 'get'
|
||||
public final char charAt(int index) {
|
||||
return get(position() + checkIndex(index, 1));
|
||||
}
|
||||
|
||||
// Should override 'X.get'
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: NonCharBuffer.java
|
||||
public abstract class NonCharBuffer implements CharSequence {
|
||||
// Not overriding charAt explicitly but inherited through kotlin.CharSequence.get
|
||||
|
||||
// Should override nothing
|
||||
public abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferXAllInherited.java
|
||||
public abstract class CharBufferXAllInherited implements CharSequence, X {
|
||||
}
|
||||
|
||||
// FILE: Y.java
|
||||
public class Y {
|
||||
protected abstract char get(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferXYAllInherited.java
|
||||
public abstract class CharBufferXYAllInherited extends Y implements CharSequence, X {
|
||||
}
|
||||
|
||||
// FILE: CharAt.java
|
||||
public interface CharAt {
|
||||
char charAt(int index);
|
||||
}
|
||||
|
||||
// FILE: CharBufferXYCharAt.java
|
||||
public class CharBufferXYCharAt extends Y implements CharSequence, X, CharAt {
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun test(
|
||||
charBuffer: CharBuffer,
|
||||
charBufferX: CharBufferX,
|
||||
nonCharSequenceBuffer: NonCharSequenceBuffer,
|
||||
nonCharBuffer: NonCharBuffer,
|
||||
charBufferXAllInherited: CharBufferXAllInherited,
|
||||
charBufferXYAllInherited: CharBufferXYAllInherited,
|
||||
charBufferXYCharAt: CharBufferXYCharAt,
|
||||
) {
|
||||
charBuffer.get(0)
|
||||
(charBuffer as CharSequence).get(0)
|
||||
|
||||
charBufferX.get(0)
|
||||
(charBufferX as CharSequence).get(0)
|
||||
|
||||
nonCharSequenceBuffer.get(0)
|
||||
nonCharSequenceBuffer.charAt(0)
|
||||
|
||||
nonCharBuffer.get(0)
|
||||
(nonCharBuffer as CharSequence).get(0)
|
||||
|
||||
charBufferXAllInherited.get(0)
|
||||
(charBufferXAllInherited as CharSequence).get(0)
|
||||
|
||||
charBufferXYAllInherited.get(0)
|
||||
(charBufferXYAllInherited as CharSequence).get(0)
|
||||
|
||||
charBufferXYCharAt.get(0)
|
||||
(charBufferXYCharAt as CharSequence).get(0)
|
||||
(charBufferXYCharAt as CharAt).charAt(0)
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
CharBuffer:
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBuffer [id: 0]
|
||||
[Enhancement]: public final operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBuffer [id: 0]
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Use site scope of kotlin/CharSequence [id: 1]
|
||||
|
||||
CharBufferX:
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferX [id: 0]
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /X [id: 1]
|
||||
[Enhancement]: public final operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferX [id: 0]
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Use site scope of kotlin/CharSequence [id: 1]
|
||||
|
||||
NonCharSequenceBuffer:
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /NonCharSequenceBuffer [id: 0]
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /X [id: 1]
|
||||
[Enhancement]: public final fun charAt(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /NonCharSequenceBuffer [id: 0]
|
||||
|
||||
NonCharBuffer:
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /NonCharBuffer [id: 0]
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /NonCharBuffer [id: 0]
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Use site scope of kotlin/CharSequence [id: 1]
|
||||
|
||||
CharBufferXAllInherited:
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferXAllInherited [id: 0]
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Use site scope of kotlin/CharSequence [id: 1]
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferXAllInherited [id: 0]
|
||||
|
||||
CharBufferXYAllInherited:
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferXYAllInherited [id: 0]
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Use site scope of kotlin/CharSequence [id: 1]
|
||||
[IntersectionOverride]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferXYAllInherited [id: 0]
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /X [id: 1]
|
||||
[Enhancement]: protected/*protected and package*/ abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /Y [id: 2]
|
||||
|
||||
CharBufferXYCharAt:
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferXYCharAt [id: 0]
|
||||
[Library]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Use site scope of kotlin/CharSequence [id: 1]
|
||||
[RenamedForOverride]: public abstract fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharAt [id: 2]
|
||||
[IntersectionOverride]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /CharBufferXYCharAt [id: 0]
|
||||
[Enhancement]: public abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /X [id: 1]
|
||||
[Enhancement]: protected/*protected and package*/ abstract operator fun get(index: R|kotlin/Int|): R|kotlin/Char| from Java enhancement scope for /Y [id: 2]
|
||||
Generated
+6
@@ -21682,6 +21682,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
public void testSizeFromKotlinOverriddenInJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/sizeFromKotlinOverriddenInJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/collectionOverrides/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -48116,6 +48116,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -51140,6 +51140,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+6
@@ -51140,6 +51140,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+5
@@ -41169,6 +41169,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
public void testValuesInsideEnum() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/valuesInsideEnum.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("weirdCharBuffers.kt")
|
||||
public void testWeirdCharBuffers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/specialBuiltins/weirdCharBuffers.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/statics")
|
||||
|
||||
Reference in New Issue
Block a user