Don't allow coercing receivers from signed to unsigned constants

This commit is contained in:
Mikhail Zarechenskiy
2020-06-03 13:32:14 +03:00
parent bfa648972f
commit e72401c5f4
4 changed files with 27 additions and 1 deletions
@@ -429,7 +429,7 @@ private fun KotlinResolutionCandidate.resolveKotlinArgument(
val unsubstitutedExpectedType = conversionDataBeforeSubtyping?.convertedType ?: candidateExpectedType
val expectedType = unsubstitutedExpectedType?.let { prepareExpectedType(it) }
val convertedArgument = if (expectedType != null && shouldRunConversionForConstants(expectedType)) {
val convertedArgument = if (expectedType != null && !isReceiver && shouldRunConversionForConstants(expectedType)) {
val convertedConstant = resolutionCallbacks.convertSignedConstantToUnsigned(argument)
if (convertedConstant != null) {
resolvedCall.registerArgumentWithConstantConversion(argument, convertedConstant)
@@ -0,0 +1,14 @@
fun UInt.fUInt() {}
fun UByte.fUByte() {}
fun UShort.fUShort() {}
fun ULong.fULong() {}
fun test() {
1.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>fUInt<!>()
1.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>fUByte<!>()
1.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>fUShort<!>()
1.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>fULong<!>()
3000000000 until <!CONSTANT_EXPECTED_TYPE_MISMATCH!>3000000004UL<!>
0 until <!CONSTANT_EXPECTED_TYPE_MISMATCH!>10u<!>
}
@@ -0,0 +1,7 @@
package
public fun test(): kotlin.Unit
public fun kotlin.UByte.fUByte(): kotlin.Unit
public fun kotlin.UInt.fUInt(): kotlin.Unit
public fun kotlin.ULong.fULong(): kotlin.Unit
public fun kotlin.UShort.fUShort(): kotlin.Unit
@@ -110,6 +110,11 @@ public class DiagnosticsWithUnsignedTypesGenerated extends AbstractDiagnosticsWi
runTest("compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/inferenceForSignedAndUnsignedTypes.kt");
}
@TestMetadata("noConversionForUnsignedTypesOnReceiver.kt")
public void testNoConversionForUnsignedTypesOnReceiver() throws Exception {
runTest("compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/noConversionForUnsignedTypesOnReceiver.kt");
}
@TestMetadata("overloadResolutionForSignedAndUnsignedTypes.kt")
public void testOverloadResolutionForSignedAndUnsignedTypes() throws Exception {
runTest("compiler/testData/diagnostics/testsWithUnsignedTypes/conversions/overloadResolutionForSignedAndUnsignedTypes.kt");