@@ -59,8 +59,7 @@ class CandidateResolver(
59
59
private val reflectionTypes : ReflectionTypes ,
60
60
private val smartCastManager : SmartCastManager
61
61
) {
62
-
63
- fun <D : CallableDescriptor , F : D > performResolutionForCandidateCall (
62
+ fun <D : CallableDescriptor > performResolutionForCandidateCall (
64
63
context : CallCandidateResolutionContext <D >,
65
64
checkArguments : CheckArgumentTypesMode
66
65
): Unit = with (context) {
@@ -99,9 +98,9 @@ class CandidateResolver(
99
98
}
100
99
101
100
private fun CallCandidateResolutionContext <* >.checkValueArguments () = checkAndReport {
102
- if (call.getTypeArguments() .isEmpty()
101
+ if (call.typeArguments .isEmpty()
103
102
&& ! candidateDescriptor.typeParameters.isEmpty()
104
- && candidateCall.getKnownTypeParametersSubstitutor() == null
103
+ && candidateCall.knownTypeParametersSubstitutor == null
105
104
) {
106
105
genericCandidateResolver.inferTypeArguments(this )
107
106
}
@@ -111,41 +110,42 @@ class CandidateResolver(
111
110
}
112
111
113
112
private fun CallCandidateResolutionContext <* >.processTypeArguments () = check {
114
- val jetTypeArguments = call.getTypeArguments()
113
+ val ktTypeArguments = call.typeArguments
115
114
if (candidateCall.knownTypeParametersSubstitutor != null ) {
116
115
candidateCall.setResultingSubstitutor(candidateCall.knownTypeParametersSubstitutor!! )
117
116
}
118
- else if (! jetTypeArguments .isEmpty()) {
117
+ else if (! ktTypeArguments .isEmpty()) {
119
118
// Explicit type arguments passed
120
119
121
120
val typeArguments = ArrayList <KotlinType >()
122
- for (projection in jetTypeArguments ) {
121
+ for (projection in ktTypeArguments ) {
123
122
val type = projection.typeReference?.let { trace.bindingContext.get(BindingContext .TYPE , it) }
124
123
? : ErrorUtils .createErrorType(" Star projection in a call" )
125
124
typeArguments.add(type)
126
125
}
127
126
128
127
val expectedTypeArgumentCount = candidateDescriptor.typeParameters.size
129
- for (index in jetTypeArguments .size.. expectedTypeArgumentCount - 1 ) {
128
+ for (index in ktTypeArguments .size.. expectedTypeArgumentCount - 1 ) {
130
129
typeArguments.add(ErrorUtils .createErrorType(
131
- " Explicit type argument expected for " + candidateDescriptor.typeParameters.get(index).name))
130
+ " Explicit type argument expected for " + candidateDescriptor.typeParameters[index].name
131
+ ))
132
132
}
133
133
val substitution = FunctionDescriptorUtil .createSubstitution(candidateDescriptor as FunctionDescriptor , typeArguments)
134
134
val substitutor = TypeSubstitutor .create(SubstitutionFilteringInternalResolveAnnotations (substitution))
135
135
136
- if (expectedTypeArgumentCount != jetTypeArguments .size) {
136
+ if (expectedTypeArgumentCount != ktTypeArguments .size) {
137
137
candidateCall.addStatus(OTHER_ERROR )
138
138
tracing.wrongNumberOfTypeArguments(trace, expectedTypeArgumentCount, candidateDescriptor)
139
139
}
140
140
else {
141
- checkGenericBoundsInAFunctionCall(jetTypeArguments , typeArguments, candidateDescriptor, substitutor, trace)
141
+ checkGenericBoundsInAFunctionCall(ktTypeArguments , typeArguments, candidateDescriptor, substitutor, trace)
142
142
}
143
143
144
144
candidateCall.setResultingSubstitutor(substitutor)
145
145
}
146
146
}
147
147
148
- private fun <D : CallableDescriptor , F : D > CallCandidateResolutionContext<D>.mapArguments ()
148
+ private fun <D : CallableDescriptor > CallCandidateResolutionContext<D>.mapArguments ()
149
149
= check {
150
150
val argumentMappingStatus = ValueArgumentsToParametersMapper .mapValueArgumentsToParameters(
151
151
call, tracing, candidateCall, Sets .newLinkedHashSet<ValueArgument >())
@@ -154,7 +154,7 @@ class CandidateResolver(
154
154
}
155
155
}
156
156
157
- private fun <D : CallableDescriptor , F : D > CallCandidateResolutionContext<D>.checkExpectedCallableType ()
157
+ private fun <D : CallableDescriptor > CallCandidateResolutionContext<D>.checkExpectedCallableType ()
158
158
= check {
159
159
if (! noExpectedType(expectedType)) {
160
160
val candidate = candidateCall.candidateDescriptor
@@ -206,15 +206,15 @@ class CandidateResolver(
206
206
) == null
207
207
208
208
private fun CallCandidateResolutionContext <* >.checkExtensionReceiver () = checkAndReport {
209
- val receiverParameter = candidateCall.getCandidateDescriptor() .extensionReceiverParameter
210
- val receiverArgument = candidateCall.getExtensionReceiver()
209
+ val receiverParameter = candidateCall.candidateDescriptor .extensionReceiverParameter
210
+ val receiverArgument = candidateCall.extensionReceiver
211
211
if (receiverParameter != null && receiverArgument == null ) {
212
- tracing.missingReceiver(candidateCall.getTrace() , receiverParameter)
212
+ tracing.missingReceiver(candidateCall.trace , receiverParameter)
213
213
OTHER_ERROR
214
214
}
215
215
else if (receiverParameter == null && receiverArgument != null ) {
216
- tracing.noReceiverAllowed(candidateCall.getTrace() )
217
- if (call.getCalleeExpression() is KtSimpleNameExpression ) {
216
+ tracing.noReceiverAllowed(candidateCall.trace )
217
+ if (call.calleeExpression is KtSimpleNameExpression ) {
218
218
RECEIVER_PRESENCE_ERROR
219
219
}
220
220
else {
@@ -228,7 +228,7 @@ class CandidateResolver(
228
228
229
229
private fun CallCandidateResolutionContext <* >.checkDispatchReceiver () = checkAndReport {
230
230
val candidateDescriptor = candidateDescriptor
231
- val dispatchReceiver = candidateCall.getDispatchReceiver()
231
+ val dispatchReceiver = candidateCall.dispatchReceiver
232
232
if (dispatchReceiver != null ) {
233
233
var nestedClass: ClassDescriptor ? = null
234
234
if (candidateDescriptor is ConstructorDescriptor
@@ -240,12 +240,12 @@ class CandidateResolver(
240
240
nestedClass = candidateDescriptor.getReferencedDescriptor()
241
241
}
242
242
if (nestedClass != null ) {
243
- tracing.nestedClassAccessViaInstanceReference(trace, nestedClass, candidateCall.getExplicitReceiverKind() )
243
+ tracing.nestedClassAccessViaInstanceReference(trace, nestedClass, candidateCall.explicitReceiverKind )
244
244
return @checkAndReport OTHER_ERROR
245
245
}
246
246
}
247
247
248
- assert ((dispatchReceiver != null ) == (candidateCall.getResultingDescriptor() .dispatchReceiverParameter != null )) {
248
+ assert ((dispatchReceiver != null ) == (candidateCall.resultingDescriptor .dispatchReceiverParameter != null )) {
249
249
" Shouldn't happen because of TaskPrioritizer: $candidateDescriptor "
250
250
}
251
251
@@ -261,17 +261,17 @@ class CandidateResolver(
261
261
if (! context.call.callElement.insideScript()) return true
262
262
263
263
// In "[email protected] ()" the error will be reported on "this@Outer" instead
264
- if (context.call.getExplicitReceiver() != null || context.call.getDispatchReceiver() != null ) return true
264
+ if (context.call.explicitReceiver != null || context.call.dispatchReceiver != null ) return true
265
265
266
- val candidateThis = getDeclaringClass(context.candidateCall.getCandidateDescriptor() )
266
+ val candidateThis = getDeclaringClass(context.candidateCall.candidateDescriptor )
267
267
if (candidateThis == null || candidateThis.kind.isSingleton) return true
268
268
269
- return DescriptorResolver .checkHasOuterClassInstance(context.scope, context.trace, context.call.getCallElement() , candidateThis)
269
+ return DescriptorResolver .checkHasOuterClassInstance(context.scope, context.trace, context.call.callElement , candidateThis)
270
270
}
271
271
272
272
private fun CallCandidateResolutionContext <* >.checkAbstractAndSuper () = check {
273
273
val descriptor = candidateDescriptor
274
- val expression = candidateCall.getCall().getCalleeExpression()
274
+ val expression = candidateCall.call.calleeExpression
275
275
276
276
if (expression is KtSimpleNameExpression ) {
277
277
// 'B' in 'class A: B()' is JetConstructorCalleeExpression
@@ -283,7 +283,7 @@ class CandidateResolver(
283
283
}
284
284
}
285
285
286
- val superDispatchReceiver = getReceiverSuper(candidateCall.getDispatchReceiver() )
286
+ val superDispatchReceiver = getReceiverSuper(candidateCall.dispatchReceiver )
287
287
if (superDispatchReceiver != null ) {
288
288
if (descriptor is MemberDescriptor && descriptor.modality == Modality .ABSTRACT ) {
289
289
tracing.abstractSuperCall(trace)
@@ -293,9 +293,9 @@ class CandidateResolver(
293
293
294
294
// 'super' cannot be passed as an argument, for receiver arguments expression typer does not track this
295
295
// See TaskPrioritizer for more
296
- val superExtensionReceiver = getReceiverSuper(candidateCall.getExtensionReceiver() )
296
+ val superExtensionReceiver = getReceiverSuper(candidateCall.extensionReceiver )
297
297
if (superExtensionReceiver != null ) {
298
- trace.report(SUPER_CANT_BE_EXTENSION_RECEIVER .on(superExtensionReceiver, superExtensionReceiver.getText() ))
298
+ trace.report(SUPER_CANT_BE_EXTENSION_RECEIVER .on(superExtensionReceiver, superExtensionReceiver.text ))
299
299
candidateCall.addStatus(OTHER_ERROR )
300
300
}
301
301
}
@@ -343,23 +343,19 @@ class CandidateResolver(
343
343
private fun <D : CallableDescriptor , C : CallResolutionContext <C >> checkValueArgumentTypes (
344
344
context : CallResolutionContext <C >,
345
345
candidateCall : MutableResolvedCall <D >,
346
- resolveFunctionArgumentBodies : ResolveArgumentsMode ): ValueArgumentsCheckingResult {
346
+ resolveFunctionArgumentBodies : ResolveArgumentsMode
347
+ ): ValueArgumentsCheckingResult {
347
348
var resultStatus = SUCCESS
348
349
val argumentTypes = Lists .newArrayList<KotlinType >()
349
- val infoForArguments = candidateCall.getDataFlowInfoForArguments()
350
- for (entry in candidateCall.getValueArguments().entries) {
351
- val parameterDescriptor = entry.key
352
- val resolvedArgument = entry.value
353
-
354
-
350
+ val infoForArguments = candidateCall.dataFlowInfoForArguments
351
+ for ((parameterDescriptor, resolvedArgument) in candidateCall.valueArguments) {
355
352
for (argument in resolvedArgument.arguments) {
356
353
val expression = argument.getArgumentExpression() ? : continue
357
354
358
355
val expectedType = getEffectiveExpectedType(parameterDescriptor, argument)
359
356
360
357
val newContext = context.replaceDataFlowInfo(infoForArguments.getInfo(argument)).replaceExpectedType(expectedType)
361
- val typeInfoForCall = argumentTypeResolver.getArgumentTypeInfo(
362
- expression, newContext, resolveFunctionArgumentBodies)
358
+ val typeInfoForCall = argumentTypeResolver.getArgumentTypeInfo(expression, newContext, resolveFunctionArgumentBodies)
363
359
val type = typeInfoForCall.type
364
360
infoForArguments.updateInfo(argument, typeInfoForCall.dataFlowInfo)
365
361
@@ -403,15 +399,13 @@ class CandidateResolver(
403
399
expression : KtExpression ,
404
400
expectedType : KotlinType ,
405
401
actualType : KotlinType ,
406
- context : ResolutionContext <* >): KotlinType ? {
402
+ context : ResolutionContext <* >
403
+ ): KotlinType ? {
407
404
val receiverToCast = ExpressionReceiver .create(KtPsiUtil .safeDeparenthesize(expression), actualType, context.trace.bindingContext)
408
405
val variants = smartCastManager.getSmartCastVariantsExcludingReceiver(context, receiverToCast)
409
- for (possibleType in variants) {
410
- if (KotlinTypeChecker .DEFAULT .isSubtypeOf(possibleType, expectedType)) {
411
- return possibleType
412
- }
406
+ return variants.firstOrNull { possibleType ->
407
+ KotlinTypeChecker .DEFAULT .isSubtypeOf(possibleType, expectedType)
413
408
}
414
- return null
415
409
}
416
410
417
411
private fun CallCandidateResolutionContext <* >.checkReceiverTypeError (): Unit = check {
@@ -421,11 +415,9 @@ class CandidateResolver(
421
415
// For the expressions like '42.(f)()' where f: String.() -> Unit we'd like to generate a type mismatch error on '1',
422
416
// not to throw away the candidate, so the following check is skipped.
423
417
if (! isInvokeCallOnExpressionWithBothReceivers(call)) {
424
- val callExtensionReceiver = candidateCall.extensionReceiver
425
- assert (callExtensionReceiver is ReceiverValue ? ) { " Expected ReceiverValue, got $callExtensionReceiver " }
426
- checkReceiverTypeError(extensionReceiver, callExtensionReceiver as ReceiverValue ? )
418
+ checkReceiverTypeError(extensionReceiver, candidateCall.extensionReceiver)
427
419
}
428
- checkReceiverTypeError(dispatchReceiver, candidateCall.getDispatchReceiver() )
420
+ checkReceiverTypeError(dispatchReceiver, candidateCall.dispatchReceiver )
429
421
}
430
422
431
423
private fun CallCandidateResolutionContext <* >.checkReceiverTypeError (
@@ -454,17 +446,20 @@ class CandidateResolver(
454
446
455
447
resultStatus = resultStatus.combine(context.checkReceiver(
456
448
candidateCall,
457
- candidateCall.getResultingDescriptor() .extensionReceiverParameter,
449
+ candidateCall.resultingDescriptor .extensionReceiverParameter,
458
450
candidateCall.extensionReceiver,
459
451
candidateCall.explicitReceiverKind.isExtensionReceiver,
460
- implicitInvokeCheck = false , isDispatchReceiver = false ))
452
+ implicitInvokeCheck = false , isDispatchReceiver = false
453
+ ))
461
454
462
- resultStatus = resultStatus.combine(context.checkReceiver(candidateCall,
463
- candidateCall.getResultingDescriptor().dispatchReceiverParameter, candidateCall.getDispatchReceiver(),
464
- candidateCall.getExplicitReceiverKind().isDispatchReceiver,
455
+ resultStatus = resultStatus.combine(context.checkReceiver(
456
+ candidateCall,
457
+ candidateCall.resultingDescriptor.dispatchReceiverParameter, candidateCall.dispatchReceiver,
458
+ candidateCall.explicitReceiverKind.isDispatchReceiver,
465
459
// for the invocation 'foo(1)' where foo is a variable of function type we should mark 'foo' if there is unsafe call error
466
- implicitInvokeCheck = context.call is CallForImplicitInvoke ,
467
- isDispatchReceiver = true ))
460
+ implicitInvokeCheck = context.call is CallForImplicitInvoke ,
461
+ isDispatchReceiver = true
462
+ ))
468
463
469
464
if (! context.isDebuggerContext
470
465
&& candidateCall.dispatchReceiver != null
@@ -571,38 +566,40 @@ class CandidateResolver(
571
566
inner class ValueArgumentsCheckingResult (val status : ResolutionStatus , val argumentTypes : List <KotlinType >)
572
567
573
568
private fun checkGenericBoundsInAFunctionCall (
574
- jetTypeArguments : List <KtTypeProjection >,
569
+ ktTypeArguments : List <KtTypeProjection >,
575
570
typeArguments : List <KotlinType >,
576
571
functionDescriptor : CallableDescriptor ,
577
572
substitutor : TypeSubstitutor ,
578
- trace : BindingTrace ) {
573
+ trace : BindingTrace
574
+ ) {
579
575
val typeParameters = functionDescriptor.typeParameters
580
- for (i in 0 .. Math .min(typeParameters.size, jetTypeArguments .size) - 1 ) {
581
- val typeParameterDescriptor = typeParameters.get(i)
582
- val typeArgument = typeArguments.get(i)
583
- val typeReference = jetTypeArguments.get(i).getTypeReference()
576
+ for (i in 0 .. Math .min(typeParameters.size, ktTypeArguments .size) - 1 ) {
577
+ val typeParameterDescriptor = typeParameters[i]
578
+ val typeArgument = typeArguments[i]
579
+ val typeReference = ktTypeArguments[i].typeReference
584
580
if (typeReference != null ) {
585
581
DescriptorResolver .checkBounds(typeReference, typeArgument, typeParameterDescriptor, substitutor, trace)
586
582
}
587
583
}
588
584
}
589
585
590
586
private fun <D : CallableDescriptor > CallCandidateResolutionContext<D>.shouldContinue () =
591
- candidateResolveMode == CandidateResolveMode .FULLY || candidateCall.getStatus() .possibleTransformToSuccess()
587
+ candidateResolveMode == CandidateResolveMode .FULLY || candidateCall.status .possibleTransformToSuccess()
592
588
593
589
private inline fun <D : CallableDescriptor > CallCandidateResolutionContext<D>.check (
594
590
checker : CallCandidateResolutionContext <D >.() -> Unit
595
591
) {
596
592
if (shouldContinue()) checker()
597
593
}
598
594
599
- private inline fun <D : CallableDescriptor > CallCandidateResolutionContext <D >.
600
- checkAndReport (checker : CallCandidateResolutionContext <D >.() -> ResolutionStatus ) {
595
+ private inline fun <D : CallableDescriptor > CallCandidateResolutionContext<D>.checkAndReport (
596
+ checker : CallCandidateResolutionContext <D >.() -> ResolutionStatus
597
+ ) {
601
598
if (shouldContinue()) {
602
599
candidateCall.addStatus(checker())
603
600
}
604
601
}
605
602
606
- private val CallCandidateResolutionContext <* >.candidateDescriptor: CallableDescriptor get() = candidateCall.getCandidateDescriptor()
607
-
603
+ private val CallCandidateResolutionContext <* >.candidateDescriptor: CallableDescriptor
604
+ get() = candidateCall.candidateDescriptor
608
605
}
0 commit comments