[FIR] KT-57568: Make K2 treat signed ints as more specific than unsigned

This is the way it works in K1.
See `OverloadingConflictResolver.kt:345`.

^KT-57568 Fixed

Merge-request: KT-MR-9395
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
This commit is contained in:
Nikolay Lunyak
2023-03-30 06:28:16 +00:00
committed by Space Team
parent 34c82011fc
commit 12b11bd034
7 changed files with 52 additions and 0 deletions
@@ -35299,6 +35299,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "native");
}
@Test
@TestMetadata("ambiguityWithUnsignedSpecificity.kt")
public void testAmbiguityWithUnsignedSpecificity() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/ambiguityWithUnsignedSpecificity.kt");
}
@Test
@TestMetadata("ArrayOfNothing.kt")
public void testArrayOfNothing() throws Exception {
@@ -35299,6 +35299,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "native");
}
@Test
@TestMetadata("ambiguityWithUnsignedSpecificity.kt")
public void testAmbiguityWithUnsignedSpecificity() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/ambiguityWithUnsignedSpecificity.kt");
}
@Test
@TestMetadata("ArrayOfNothing.kt")
public void testArrayOfNothing() throws Exception {
@@ -35299,6 +35299,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("ambiguityWithUnsignedSpecificity.kt")
public void testAmbiguityWithUnsignedSpecificity() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/ambiguityWithUnsignedSpecificity.kt");
}
@Test
@TestMetadata("ArrayOfNothing.kt")
public void testArrayOfNothing() throws Exception {
@@ -35395,6 +35395,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("ambiguityWithUnsignedSpecificity.kt")
public void testAmbiguityWithUnsignedSpecificity() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/ambiguityWithUnsignedSpecificity.kt");
}
@Test
@TestMetadata("ArrayOfNothing.kt")
public void testArrayOfNothing() throws Exception {
@@ -12,6 +12,8 @@ import org.jetbrains.kotlin.fir.resolve.FirSamResolver
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.name.StandardClassIds.Byte
import org.jetbrains.kotlin.name.StandardClassIds.Double
import org.jetbrains.kotlin.name.StandardClassIds.Float
@@ -79,6 +81,12 @@ abstract class AbstractConeCallConflictResolver(
val specificClassId = specific.lowerBoundIfFlexible().classId ?: return false
val generalClassId = general.upperBoundIfFlexible().classId ?: return false
// any signed >= any unsigned
if (!specificClassId.isUnsigned && generalClassId.isUnsigned) {
return true
}
// int >= long, int >= short, short >= byte
if (specificClassId == Int) {
@@ -99,6 +107,8 @@ abstract class AbstractConeCallConflictResolver(
return specificClassId == Double && generalClassId == Float
}
private val ClassId.isUnsigned get() = this in StandardClassIds.unsignedTypes
}
protected fun createFlatSignature(call: Candidate): FlatSignature<Candidate> {
@@ -0,0 +1,12 @@
// FIR_IDENTICAL
// ISSUE: KT-57568
fun <T, K> T.convert(): K = null!!
fun of(size: ULong) {
of(size.convert())
}
fun of(size: Int) {}
fun of(size: Long) {}
@@ -36143,6 +36143,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("ambiguityWithUnsignedSpecificity.kt")
public void testAmbiguityWithUnsignedSpecificity() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/ambiguityWithUnsignedSpecificity.kt");
}
@Test
@TestMetadata("ArrayOfNothing.kt")
public void testArrayOfNothing() throws Exception {