Introduce call checker for Unit-conversions

This commit is contained in:
Mikhail Zarechenskiy
2020-06-02 16:15:36 +03:00
parent 6b0a803d14
commit bfa648972f
14 changed files with 210 additions and 1 deletions
@@ -75,6 +75,8 @@ object UnitTypeConversions : ParameterTypeConversion {
suspendFunction = expectedParameterType.isSuspendFunctionType
)
candidate.resolvedCall.registerArgumentWithUnitConversion(argument, nonUnitReturnedParameterType)
candidate.addDiagnostic(LowerPriorityToPreserveCompatibility)
return nonUnitReturnedParameterType
@@ -69,6 +69,7 @@ abstract class ResolvedCallAtom : ResolvedAtom() {
abstract val knownParametersSubstitutor: TypeSubstitutor
abstract val argumentsWithConversion: Map<KotlinCallArgument, SamConversionDescription>
abstract val argumentsWithSuspendConversion: Map<KotlinCallArgument, UnwrappedType>
abstract val argumentsWithUnitConversion: Map<KotlinCallArgument, UnwrappedType>
abstract val argumentsWithConstantConversion: Map<KotlinCallArgument, IntegerValueTypeConstant>
}
@@ -193,6 +193,7 @@ class MutableResolvedCallAtom(
lateinit var argumentToCandidateParameter: Map<KotlinCallArgument, ValueParameterDescriptor>
private var samAdapterMap: HashMap<KotlinCallArgument, SamConversionDescription>? = null
private var suspendAdapterMap: HashMap<KotlinCallArgument, UnwrappedType>? = null
private var unitAdapterMap: HashMap<KotlinCallArgument, UnwrappedType>? = null
private var signedUnsignedConstantConversions: HashMap<KotlinCallArgument, IntegerValueTypeConstant>? = null
val hasSamConversion: Boolean
@@ -207,6 +208,9 @@ class MutableResolvedCallAtom(
override val argumentsWithSuspendConversion: Map<KotlinCallArgument, UnwrappedType>
get() = suspendAdapterMap ?: emptyMap()
override val argumentsWithUnitConversion: Map<KotlinCallArgument, UnwrappedType>
get() = unitAdapterMap ?: emptyMap()
override val argumentsWithConstantConversion: Map<KotlinCallArgument, IntegerValueTypeConstant>
get() = signedUnsignedConstantConversions ?: emptyMap()
@@ -224,6 +228,13 @@ class MutableResolvedCallAtom(
suspendAdapterMap!![argument] = convertedType
}
fun registerArgumentWithUnitConversion(argument: KotlinCallArgument, convertedType: UnwrappedType) {
if (unitAdapterMap == null)
unitAdapterMap = hashMapOf()
unitAdapterMap!![argument] = convertedType
}
fun registerArgumentWithConstantConversion(argument: KotlinCallArgument, convertedConstant: IntegerValueTypeConstant) {
if (signedUnsignedConstantConversions == null)
signedUnsignedConstantConversions = hashMapOf()