[FE] Fill DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP only with CR enabled
This commit is contained in:
committed by
TeamCityServer
parent
9e2271399e
commit
2d088196ce
@@ -263,7 +263,7 @@ public interface BindingContext {
|
||||
.setFurtherLookupSlices(DECLARATIONS_TO_DESCRIPTORS)
|
||||
.build();
|
||||
|
||||
WritableSlice<DeclarationDescriptor, Multimap<String, ReceiverParameterDescriptor>> DESCRIPTOR_TO_NAMED_RECEIVERS = Slices.createSimpleSlice();
|
||||
WritableSlice<DeclarationDescriptor, Multimap<String, ReceiverParameterDescriptor>> DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP = Slices.createSimpleSlice();
|
||||
WritableSlice<KtReferenceExpression, PsiElement> LABEL_TARGET = Slices.createSimpleSlice();
|
||||
WritableSlice<KtReferenceExpression, Collection<? extends PsiElement>> AMBIGUOUS_LABEL_TARGET = Slices.createSimpleSlice();
|
||||
WritableSlice<ValueParameterDescriptor, PropertyDescriptor> VALUE_PARAMETER_AS_PROPERTY = Slices.createSimpleSlice();
|
||||
|
||||
@@ -959,8 +959,6 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
Multimap<String, ReceiverParameterDescriptor> nameToReceiverMap = HashMultimap.create();
|
||||
|
||||
KtTypeReference receiverTypeRef = variableDeclaration.getReceiverTypeReference();
|
||||
ReceiverParameterDescriptor receiverDescriptor = null;
|
||||
if (receiverTypeRef != null) {
|
||||
@@ -969,16 +967,38 @@ public class DescriptorResolver {
|
||||
receiverDescriptor = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
String receiverName = receiverTypeRef.nameForReceiverLabel();
|
||||
if (receiverName != null) {
|
||||
nameToReceiverMap.put(receiverName, receiverDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
List<KtContextReceiver> contextReceivers = variableDeclaration.getContextReceivers();
|
||||
List<ReceiverParameterDescriptor> contextReceiverDescriptors =
|
||||
createReceiverDescriptorsForProperty(propertyDescriptor, scopeForDeclarationResolutionWithTypeParameters, trace,
|
||||
contextReceivers, nameToReceiverMap);
|
||||
List<ReceiverParameterDescriptor> contextReceiverDescriptors = contextReceivers.stream()
|
||||
.map(contextReceiver -> {
|
||||
KtTypeReference typeReference = contextReceiver.typeReference();
|
||||
if (typeReference == null) {
|
||||
return null;
|
||||
}
|
||||
KotlinType type = typeResolver.resolveType(scopeForDeclarationResolutionWithTypeParameters, typeReference, trace, true);
|
||||
AnnotationSplitter splitter = new AnnotationSplitter(storageManager, type.getAnnotations(), EnumSet.of(RECEIVER));
|
||||
return DescriptorFactory.createContextReceiverParameterForCallable(
|
||||
propertyDescriptor, type, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.ContextReceivers)) {
|
||||
Multimap<String, ReceiverParameterDescriptor> nameToReceiverMap = HashMultimap.create();
|
||||
if (receiverTypeRef != null) {
|
||||
String receiverName = receiverTypeRef.nameForReceiverLabel();
|
||||
if (receiverName != null) {
|
||||
nameToReceiverMap.put(receiverName, receiverDescriptor);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < contextReceivers.size(); i++) {
|
||||
String contextReceiverName = contextReceivers.get(i).name();
|
||||
if (contextReceiverName != null) {
|
||||
nameToReceiverMap.put(contextReceiverName, contextReceiverDescriptors.get(i));
|
||||
}
|
||||
}
|
||||
trace.record(DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP, propertyDescriptor, nameToReceiverMap);
|
||||
}
|
||||
|
||||
LexicalScope scopeForInitializer = ScopeUtils.makeScopeForPropertyInitializer(scopeForInitializerResolutionWithTypeParameters, propertyDescriptor);
|
||||
KotlinType propertyType = propertyInfo.getVariableType();
|
||||
@@ -1027,41 +1047,10 @@ public class DescriptorResolver {
|
||||
new FieldDescriptorImpl(annotationSplitter.getAnnotationsForTarget(FIELD), propertyDescriptor),
|
||||
new FieldDescriptorImpl(annotationSplitter.getAnnotationsForTarget(PROPERTY_DELEGATE_FIELD), propertyDescriptor)
|
||||
);
|
||||
trace.record(DESCRIPTOR_TO_NAMED_RECEIVERS, propertyDescriptor, nameToReceiverMap);
|
||||
trace.record(BindingContext.VARIABLE, variableDeclaration, propertyDescriptor);
|
||||
return propertyDescriptor;
|
||||
}
|
||||
|
||||
private List<ReceiverParameterDescriptor> createReceiverDescriptorsForProperty(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull LexicalScope scopeForResolution,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull List<KtContextReceiver> contextReceivers,
|
||||
@NotNull Multimap<String, ReceiverParameterDescriptor> labelNameToReceiverMap
|
||||
) {
|
||||
Map<KtContextReceiver, KotlinType> contextReceiversToTypes = new LinkedHashMap<>();
|
||||
for (KtContextReceiver contextReceiver: contextReceivers) {
|
||||
KtTypeReference typeReference = contextReceiver.typeReference();
|
||||
if (typeReference == null) {
|
||||
continue;
|
||||
}
|
||||
KotlinType kotlinType = typeResolver.resolveType(scopeForResolution, typeReference, trace, true);
|
||||
contextReceiversToTypes.put(contextReceiver, kotlinType);
|
||||
}
|
||||
return Lists.reverse(contextReceivers).stream().map(contextReceiver -> {
|
||||
KotlinType receiverType = contextReceiversToTypes.get(contextReceiver);
|
||||
AnnotationSplitter splitter = new AnnotationSplitter(storageManager, receiverType.getAnnotations(), EnumSet.of(RECEIVER));
|
||||
ReceiverParameterDescriptor receiverDescriptor = DescriptorFactory.createContextReceiverParameterForCallable(
|
||||
propertyDescriptor, receiverType, splitter.getAnnotationsForTarget(RECEIVER)
|
||||
);
|
||||
String contextReceiverName = contextReceiver.name();
|
||||
if (contextReceiverName != null) {
|
||||
labelNameToReceiverMap.put(contextReceiverName, receiverDescriptor);
|
||||
}
|
||||
return receiverDescriptor;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/*package*/ static KotlinType transformAnonymousTypeIfNeeded(
|
||||
@NotNull DeclarationDescriptorWithVisibility descriptor,
|
||||
|
||||
@@ -256,7 +256,7 @@ class FunctionDescriptorResolver(
|
||||
}
|
||||
}
|
||||
|
||||
trace.record(BindingContext.DESCRIPTOR_TO_NAMED_RECEIVERS, functionDescriptor, labelNameToReceiverMap)
|
||||
trace.record(BindingContext.DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP, functionDescriptor, labelNameToReceiverMap)
|
||||
}
|
||||
|
||||
functionDescriptor.initialize(
|
||||
|
||||
+1
-1
@@ -317,7 +317,7 @@ private fun findReceiverByLabelOrGetDefault(
|
||||
labelName: String
|
||||
): ReceiverParameterDescriptor {
|
||||
val labelNameToReceiverMap = bindingContext.get(
|
||||
BindingContext.DESCRIPTOR_TO_NAMED_RECEIVERS,
|
||||
BindingContext.DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP,
|
||||
if (descriptorOfThisReceiver is PropertyAccessorDescriptor) descriptorOfThisReceiver.correspondingProperty else descriptorOfThisReceiver
|
||||
)
|
||||
return labelNameToReceiverMap?.get(labelName)?.singleOrNull()
|
||||
|
||||
@@ -185,7 +185,7 @@ object LabelResolver {
|
||||
val declarationDescriptor = context.trace.bindingContext[DECLARATION_TO_DESCRIPTOR, element]
|
||||
if (declarationDescriptor is FunctionDescriptor) {
|
||||
val labelNameToReceiverMap = context.trace.bindingContext[
|
||||
DESCRIPTOR_TO_NAMED_RECEIVERS,
|
||||
DESCRIPTOR_TO_CONTEXT_RECEIVER_MAP,
|
||||
if (declarationDescriptor is PropertyAccessorDescriptor) declarationDescriptor.correspondingProperty else declarationDescriptor
|
||||
]
|
||||
val thisReceivers = labelNameToReceiverMap?.get(labelName.identifier)
|
||||
|
||||
@@ -13,5 +13,5 @@ public interface B {
|
||||
@kotlin.Metadata
|
||||
public final class PropertyKt {
|
||||
// source: 'property.kt'
|
||||
public final static method getC(@org.jetbrains.annotations.NotNull p0: B, @org.jetbrains.annotations.NotNull p1: A): int
|
||||
public final static method getC(@org.jetbrains.annotations.NotNull p0: A, @org.jetbrains.annotations.NotNull p1: B): int
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package
|
||||
|
||||
context(A) public val a: kotlin.Int = 1
|
||||
context(B, A) public var b: kotlin.Int
|
||||
context(B, A) public val c: kotlin.Int
|
||||
context(A, B) public var b: kotlin.Int
|
||||
context(A, B) public val c: kotlin.Int
|
||||
|
||||
public interface A {
|
||||
public abstract fun a(): kotlin.Int
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
context(B, A<kotlin.String>, A<kotlin.Int>) public val C.p: kotlin.Int
|
||||
context(A<kotlin.Int>, A<kotlin.String>, B) public val C.p: kotlin.Int
|
||||
context(A<kotlin.Int>, A<kotlin.String>, B) public fun f(): kotlin.Unit
|
||||
|
||||
public final class A</*0*/ T> {
|
||||
|
||||
compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.txt
Vendored
+3
-3
@@ -1,8 +1,8 @@
|
||||
package
|
||||
|
||||
context(B, A<kotlin.String>) public var p: kotlin.Int
|
||||
context(B, A<kotlin.String>, A<kotlin.Int>) public var p: kotlin.Int
|
||||
context(B, A<kotlin.String>, A<kotlin.Int>) public val C.p: kotlin.Int
|
||||
context(A<kotlin.Int>, A<kotlin.String>, B) public var p: kotlin.Int
|
||||
context(A<kotlin.String>, B) public var p: kotlin.Int
|
||||
context(A<kotlin.Int>, A<kotlin.String>, B) public val C.p: kotlin.Int
|
||||
|
||||
public final class A</*0*/ T> {
|
||||
public constructor A</*0*/ T>(/*0*/ a: T)
|
||||
|
||||
@@ -34,16 +34,16 @@ FILE fqName:<root> fileName:/property.kt
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
PROPERTY name:c visibility:public modality:FINAL [val]
|
||||
FUN name:<get-c> visibility:public modality:FINAL <> (<this>:<root>.B, <this>:<root>.A) returnType:kotlin.Int
|
||||
FUN name:<get-c> visibility:public modality:FINAL <> (<this>:<root>.A, <this>:<root>.B) returnType:kotlin.Int
|
||||
correspondingProperty: PROPERTY name:c visibility:public modality:FINAL [val]
|
||||
contextReceiverParametersCount: 2
|
||||
VALUE_PARAMETER name:<this> index:0 type:<root>.B
|
||||
VALUE_PARAMETER name:<this> index:1 type:<root>.A
|
||||
VALUE_PARAMETER name:<this> index:0 type:<root>.A
|
||||
VALUE_PARAMETER name:<this> index:1 type:<root>.B
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-c> (<this>: <root>.B, <this>: <root>.A): kotlin.Int declared in <root>'
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-c> (<this>: <root>.A, <this>: <root>.B): kotlin.Int declared in <root>'
|
||||
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS
|
||||
$this: CALL 'public abstract fun a (): kotlin.Int declared in <root>.A' type=kotlin.Int origin=null
|
||||
$this: TYPE_OP type=<root>.A origin=IMPLICIT_CAST typeOperand=<root>.A
|
||||
GET_VAR '<this>: <root>.A declared in <root>.<get-c>' type=<root>.B origin=null
|
||||
$this: GET_VAR '<this>: <root>.A declared in <root>.<get-c>' type=<root>.A origin=null
|
||||
other: CALL 'public abstract fun b (): kotlin.Int declared in <root>.B' type=kotlin.Int origin=null
|
||||
$this: GET_VAR '<this>: <root>.B declared in <root>.<get-c>' type=<root>.B origin=null
|
||||
$this: TYPE_OP type=<root>.B origin=IMPLICIT_CAST typeOperand=<root>.B
|
||||
GET_VAR '<this>: <root>.B declared in <root>.<get-c>' type=<root>.A origin=null
|
||||
|
||||
@@ -9,6 +9,6 @@ interface B {
|
||||
}
|
||||
|
||||
val c: Int
|
||||
get(<this>: B, <this>: A): Int {
|
||||
return <this> /*as A */.a().plus(other = <this>.b())
|
||||
get(<this>: A, <this>: B): Int {
|
||||
return <this>.a().plus(other = <this> /*as B */.b())
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
FILE fqName:<root> fileName:/property.kt
|
||||
CLASS INTERFACE name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A
|
||||
FUN name:a visibility:public modality:ABSTRACT <> ($this:<root>.A) returnType:kotlin.Int
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.A
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS INTERFACE name:B modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.B
|
||||
FUN name:b visibility:public modality:ABSTRACT <> ($this:<root>.B) returnType:kotlin.Int
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.B
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
PROPERTY name:c visibility:public modality:FINAL [val]
|
||||
FUN name:<get-c> visibility:public modality:FINAL <> (<this>:<root>.B, <this>:<root>.A) returnType:kotlin.Int
|
||||
correspondingProperty: PROPERTY name:c visibility:public modality:FINAL [val]
|
||||
VALUE_PARAMETER name:<this> index:0 type:<root>.B
|
||||
VALUE_PARAMETER name:<this> index:1 type:<root>.A
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-c> (<this>: <root>.B, <this>: <root>.A): kotlin.Int declared in <root>'
|
||||
CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS
|
||||
$this: CALL 'public abstract fun a (): kotlin.Int declared in <root>.A' type=kotlin.Int origin=null
|
||||
$this: TYPE_OP type=<root>.A origin=IMPLICIT_CAST typeOperand=<root>.A
|
||||
GET_VAR '<this>: <root>.A declared in <root>.<get-c>' type=<root>.B origin=null
|
||||
other: CALL 'public abstract fun b (): kotlin.Int declared in <root>.B' type=kotlin.Int origin=null
|
||||
$this: GET_VAR '<this>: <root>.B declared in <root>.<get-c>' type=<root>.B origin=null
|
||||
+4
-4
@@ -111,13 +111,13 @@ FILE fqName:<root> fileName:/thisWithCustomLabel.kt
|
||||
CALL 'public final fun <get-b> (): kotlin.Any declared in <root>.B' type=kotlin.Any origin=GET_PROPERTY
|
||||
$this: GET_VAR '<this>: <root>.B declared in <root>.f' type=<root>.B origin=null
|
||||
PROPERTY name:p visibility:public modality:FINAL [val]
|
||||
FUN name:<get-p> visibility:public modality:FINAL <> ($receiver:<root>.C, <this>:<root>.B, <this>:<root>.A<kotlin.String>, <this>:<root>.A<kotlin.Int>) returnType:kotlin.Int
|
||||
FUN name:<get-p> visibility:public modality:FINAL <> ($receiver:<root>.C, <this>:<root>.A<kotlin.Int>, <this>:<root>.A<kotlin.String>, <this>:<root>.B) returnType:kotlin.Int
|
||||
correspondingProperty: PROPERTY name:p visibility:public modality:FINAL [val]
|
||||
contextReceiverParametersCount: 3
|
||||
$receiver: VALUE_PARAMETER name:<this> type:<root>.C
|
||||
VALUE_PARAMETER name:<this> index:0 type:<root>.B
|
||||
VALUE_PARAMETER name:<this> index:0 type:<root>.A<kotlin.Int>
|
||||
VALUE_PARAMETER name:<this> index:1 type:<root>.A<kotlin.String>
|
||||
VALUE_PARAMETER name:<this> index:2 type:<root>.A<kotlin.Int>
|
||||
VALUE_PARAMETER name:<this> index:2 type:<root>.B
|
||||
BLOCK_BODY
|
||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
CALL 'public open fun toFloat (): kotlin.Float declared in kotlin.Int' type=kotlin.Float origin=null
|
||||
@@ -139,5 +139,5 @@ FILE fqName:<root> fileName:/thisWithCustomLabel.kt
|
||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
CALL 'public final fun <get-c> (): kotlin.Any declared in <root>.C' type=kotlin.Any origin=GET_PROPERTY
|
||||
$this: GET_VAR '<this>: <root>.C declared in <root>.<get-p>' type=<root>.C origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-p> (<this>: <root>.B, <this>: <root>.A<kotlin.String>, <this>: <root>.A<kotlin.Int>): kotlin.Int declared in <root>'
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-p> (<this>: <root>.A<kotlin.Int>, <this>: <root>.A<kotlin.String>, <this>: <root>.B): kotlin.Int declared in <root>'
|
||||
CONST Int type=kotlin.Int value=1
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ fun f(<this>: A<Int>, <this>: A<String>, <this>: B) {
|
||||
}
|
||||
|
||||
val C.p: Int
|
||||
get(<this>: B, <this>: A<String>, <this>: A<Int>): Int {
|
||||
get(<this>: A<Int>, <this>: A<String>, <this>: B): Int {
|
||||
<this>.<get-a>().toFloat() /*~> Unit */
|
||||
<this>.<get-a>().<get-length>() /*~> Unit */
|
||||
<this>.<get-b>() /*~> Unit */
|
||||
|
||||
Reference in New Issue
Block a user