From a502405779e36c4545761c576e01324c992fe775 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Thu, 5 Nov 2015 20:35:22 +0300 Subject: [PATCH] Fixed scope creations for properties scopes. --- .../kotlin/resolve/BodyResolver.java | 60 +++++----- .../resolve/DelegatedPropertyResolver.java | 23 ++-- .../kotlin/resolve/DescriptorResolver.java | 40 +++---- .../kotlin/resolve/scopes/JetScopeUtils.java | 108 +++++------------- .../jetbrains/kotlin/resolve/scopes/Scopes.kt | 6 +- .../RedeclaredTypeParameters.kt | 2 +- .../initializerScopeOfExtensionProperty.kt | 6 +- .../initializerScopeOfExtensionProperty.txt | 6 +- .../dynamicTypes/conventions.dynamic.txt | 10 +- .../kotlin/idea/kdoc/KDocReference.kt | 4 +- .../idea/project/ResolveElementCache.kt | 17 +-- .../ReplaceWithAnnotationAnalyzer.kt | 3 +- 12 files changed, 109 insertions(+), 176 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index cf7234171bd..c72f6ea879f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -576,9 +576,8 @@ public class BodyResolver { }); } - private void resolveProperty( + public void resolveProperty( @NotNull BodiesResolveContext c, - @Nullable LexicalScope parentScope, @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor ) { @@ -586,18 +585,16 @@ public class BodyResolver { PreliminaryDeclarationVisitor.Companion.createForDeclaration(property, trace); KtExpression initializer = property.getInitializer(); - LexicalScope propertyScope = getScopeForProperty(c, property); - if (parentScope == null) { - parentScope = propertyScope; - } + LexicalScope propertyHeaderScope = JetScopeUtils.makeScopeForPropertyHeader(getScopeForProperty(c, property), propertyDescriptor); + if (initializer != null) { - resolvePropertyInitializer(c.getOuterDataFlowInfo(), property, propertyDescriptor, initializer, propertyScope); + resolvePropertyInitializer(c.getOuterDataFlowInfo(), property, propertyDescriptor, initializer, propertyHeaderScope); } KtExpression delegateExpression = property.getDelegateExpression(); if (delegateExpression != null) { assert initializer == null : "Initializer should be null for delegated property : " + property.getText(); - resolvePropertyDelegate(c.getOuterDataFlowInfo(), property, propertyDescriptor, delegateExpression, parentScope, propertyScope); + resolvePropertyDelegate(c.getOuterDataFlowInfo(), property, propertyDescriptor, delegateExpression, propertyHeaderScope); } resolvePropertyAccessors(c, property, propertyDescriptor); @@ -616,7 +613,7 @@ public class BodyResolver { PropertyDescriptor propertyDescriptor = c.getProperties().get(property); assert propertyDescriptor != null; - resolveProperty(c, classDescriptor.getScopeForMemberDeclarationResolution(), property, propertyDescriptor); + resolveProperty(c, property, propertyDescriptor); processed.add(property); } } @@ -628,19 +625,21 @@ public class BodyResolver { PropertyDescriptor propertyDescriptor = entry.getValue(); - resolveProperty(c, null, property, propertyDescriptor); + resolveProperty(c, property, propertyDescriptor); } } - private LexicalScope makeScopeForPropertyAccessor( + private static LexicalScope makeScopeForPropertyAccessor( @NotNull BodiesResolveContext c, @NotNull KtPropertyAccessor accessor, @NotNull PropertyDescriptor descriptor ) { LexicalScope accessorDeclaringScope = c.getDeclaringScope(accessor); assert accessorDeclaringScope != null : "Scope for accessor " + accessor.getText() + " should exists"; - return JetScopeUtils.makeScopeForPropertyAccessor(descriptor, accessorDeclaringScope, trace); + LexicalScope headerScope = JetScopeUtils.makeScopeForPropertyHeader(accessorDeclaringScope, descriptor); + return new LexicalScopeImpl(headerScope, descriptor, true, descriptor.getExtensionReceiverParameter(), + LexicalScopeKind.PROPERTY_ACCESSOR); } - public void resolvePropertyAccessors( + private void resolvePropertyAccessors( @NotNull BodiesResolveContext c, @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor @@ -683,54 +682,51 @@ public class BodyResolver { }); } - public void resolvePropertyDelegate( + private void resolvePropertyDelegate( @NotNull DataFlowInfo outerDataFlowInfo, - @NotNull KtProperty jetProperty, + @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor, @NotNull KtExpression delegateExpression, - @NotNull LexicalScope parentScopeForAccessor, - @NotNull LexicalScope propertyScope + @NotNull LexicalScope propertyHeaderScope ) { - KtPropertyAccessor getter = jetProperty.getGetter(); + KtPropertyAccessor getter = property.getGetter(); if (getter != null && getter.hasBody()) { trace.report(ACCESSOR_FOR_DELEGATED_PROPERTY.on(getter)); } - KtPropertyAccessor setter = jetProperty.getSetter(); + KtPropertyAccessor setter = property.getSetter(); if (setter != null && setter.hasBody()) { trace.report(ACCESSOR_FOR_DELEGATED_PROPERTY.on(setter)); } - LexicalScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer( - propertyDescriptor, propertyScope, propertyDescriptor.getTypeParameters(), null, trace); - LexicalScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor( - propertyDescriptor, parentScopeForAccessor, trace); + LexicalScope delegateFunctionsScope = JetScopeUtils.makeScopeForDelegateConventionFunctions(propertyHeaderScope, propertyDescriptor); + + LexicalScope initializerScope = JetScopeUtils.makeScopeForPropertyInitializer(propertyHeaderScope, propertyDescriptor); KotlinType delegateType = delegatedPropertyResolver.resolveDelegateExpression( - delegateExpression, jetProperty, propertyDescriptor, propertyDeclarationInnerScope, accessorScope, trace, + delegateExpression, property, propertyDescriptor, initializerScope, trace, outerDataFlowInfo); delegatedPropertyResolver.resolveDelegatedPropertyGetMethod(propertyDescriptor, delegateExpression, delegateType, - trace, accessorScope); + trace, delegateFunctionsScope); - if (jetProperty.isVar()) { + if (property.isVar()) { delegatedPropertyResolver.resolveDelegatedPropertySetMethod(propertyDescriptor, delegateExpression, delegateType, - trace, accessorScope); + trace, delegateFunctionsScope); } delegatedPropertyResolver.resolveDelegatedPropertyPDMethod(propertyDescriptor, delegateExpression, delegateType, - trace, accessorScope); + trace, delegateFunctionsScope); } - public void resolvePropertyInitializer( + private void resolvePropertyInitializer( @NotNull DataFlowInfo outerDataFlowInfo, @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor, @NotNull KtExpression initializer, - @NotNull LexicalScope scope + @NotNull LexicalScope propertyHeader ) { - LexicalScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer( - propertyDescriptor, scope, propertyDescriptor.getTypeParameters(), null, trace); + LexicalScope propertyDeclarationInnerScope = JetScopeUtils.makeScopeForPropertyInitializer(propertyHeader, propertyDescriptor); KotlinType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; if (propertyDescriptor.getCompileTimeInitializer() == null) { expressionTypingServices.getType(propertyDeclarationInnerScope, initializer, expectedTypeForInitializer, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java index e937bec3c79..4963b1f3e6d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java @@ -33,7 +33,10 @@ import org.jetbrains.kotlin.resolve.calls.inference.TypeVariableKt; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo; +import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils; import org.jetbrains.kotlin.resolve.scopes.LexicalScope; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl; +import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.kotlin.resolve.validation.OperatorValidator; import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator; @@ -87,9 +90,9 @@ public class DelegatedPropertyResolver { @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @NotNull BindingTrace trace, - @NotNull LexicalScope scope + @NotNull LexicalScope delegateFunctionsScope ) { - resolveDelegatedPropertyConventionMethod(propertyDescriptor, delegateExpression, delegateType, trace, scope, true); + resolveDelegatedPropertyConventionMethod(propertyDescriptor, delegateExpression, delegateType, trace, delegateFunctionsScope, true); ResolvedCall resolvedCall = trace.getBindingContext().get(DELEGATED_PROPERTY_RESOLVED_CALL, propertyDescriptor.getGetter()); return resolvedCall != null ? resolvedCall.getResultingDescriptor().getReturnType() : null; @@ -311,24 +314,23 @@ public class DelegatedPropertyResolver { return builder.toString(); } - @Nullable + @NotNull public KotlinType resolveDelegateExpression( @NotNull KtExpression delegateExpression, @NotNull KtProperty jetProperty, @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope propertyDeclarationInnerScope, - @NotNull LexicalScope accessorScope, + @NotNull LexicalScope scopeForDelegate, @NotNull BindingTrace trace, @NotNull DataFlowInfo dataFlowInfo ) { TemporaryBindingTrace traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property"); KtExpression calleeExpression = CallUtilKt.getCalleeExpressionIfAny(delegateExpression); ConstraintSystemCompleter completer = createConstraintSystemCompleter( - jetProperty, propertyDescriptor, delegateExpression, accessorScope, trace); + jetProperty, propertyDescriptor, delegateExpression, scopeForDelegate, trace); if (calleeExpression != null) { traceToResolveDelegatedProperty.record(CONSTRAINT_SYSTEM_COMPLETER, calleeExpression, completer); } - KotlinType delegateType = expressionTypingServices.safeGetType(propertyDeclarationInnerScope, delegateExpression, NO_EXPECTED_TYPE, + KotlinType delegateType = expressionTypingServices.safeGetType(scopeForDelegate, delegateExpression, NO_EXPECTED_TYPE, dataFlowInfo, traceToResolveDelegatedProperty); traceToResolveDelegatedProperty.commit(new TraceEntryFilter() { @Override @@ -344,9 +346,10 @@ public class DelegatedPropertyResolver { @NotNull KtProperty property, @NotNull final PropertyDescriptor propertyDescriptor, @NotNull final KtExpression delegateExpression, - @NotNull final LexicalScope accessorScope, + @NotNull LexicalScope scopeForDelegate, @NotNull final BindingTrace trace ) { + final LexicalScope delegateFunctionsScope = JetScopeUtils.makeScopeForDelegateConventionFunctions(scopeForDelegate, propertyDescriptor); final KotlinType expectedType = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; return new ConstraintSystemCompleter() { @Override @@ -364,7 +367,7 @@ public class DelegatedPropertyResolver { TemporaryBindingTrace.create(trace, "Trace to resolve delegated property convention methods"); OverloadResolutionResults getMethodResults = getDelegatedPropertyConventionMethod( - propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, + propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, delegateFunctionsScope, true, false ); @@ -388,7 +391,7 @@ public class DelegatedPropertyResolver { OverloadResolutionResults setMethodResults = getDelegatedPropertyConventionMethod( - propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, accessorScope, + propertyDescriptor, delegateExpression, returnType, traceToResolveConventionMethods, delegateFunctionsScope, false, false ); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index e9f7246a331..c10504723f9 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -46,10 +46,7 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue; import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator; import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsKt; import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil; -import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils; -import org.jetbrains.kotlin.resolve.scopes.LexicalScope; -import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind; -import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope; +import org.jetbrains.kotlin.resolve.scopes.*; import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt; import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt; import org.jetbrains.kotlin.storage.StorageManager; @@ -796,12 +793,9 @@ public class DescriptorResolver { ReceiverParameterDescriptor receiverDescriptor = DescriptorFactory.createExtensionReceiverParameterForCallable(propertyDescriptor, receiverType); - ReceiverParameterDescriptor implicitInitializerReceiver = property.hasDelegate() ? null : receiverDescriptor; - - LexicalScope propertyScope = JetScopeUtils.getPropertyDeclarationInnerScope(propertyDescriptor, scope, typeParameterDescriptors, - implicitInitializerReceiver, trace); - - KotlinType type = getVariableType(propertyDescriptor, propertyScope, property, dataFlowInfo, true, trace); + KotlinType type = getVariableType(propertyDescriptor, + JetScopeUtils.makeScopeForPropertyInitializer(scopeWithTypeParameters, propertyDescriptor), + property, dataFlowInfo, true, trace); propertyDescriptor.setType(type, typeParameterDescriptors, getDispatchReceiverParameterIfNeeded(containingDeclaration), receiverDescriptor); @@ -836,7 +830,7 @@ public class DescriptorResolver { @NotNull private KotlinType getVariableType( @NotNull final VariableDescriptorWithInitializerImpl variableDescriptor, - @NotNull final LexicalScope scope, + @NotNull final LexicalScope scopeForInitializer, @NotNull final KtVariableDeclaration variable, @NotNull final DataFlowInfo dataFlowInfo, boolean notLocal, @@ -856,7 +850,7 @@ public class DescriptorResolver { new Function0() { @Override public KotlinType invoke() { - return resolveDelegatedPropertyType(property, (PropertyDescriptor) variableDescriptor, scope, + return resolveDelegatedPropertyType(property, (PropertyDescriptor) variableDescriptor, scopeForInitializer, property.getDelegateExpression(), dataFlowInfo, trace); } }); @@ -877,23 +871,23 @@ public class DescriptorResolver { public KotlinType invoke() { PreliminaryDeclarationVisitor.Companion.createForDeclaration(variable, trace); KotlinType - initializerType = resolveInitializerType(scope, variable.getInitializer(), dataFlowInfo, trace); - setConstantForVariableIfNeeded(variableDescriptor, scope, variable, dataFlowInfo, initializerType, trace); + initializerType = resolveInitializerType(scopeForInitializer, variable.getInitializer(), dataFlowInfo, trace); + setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, initializerType, trace); return transformAnonymousTypeIfNeeded(variableDescriptor, variable, initializerType, trace); } } ); } else { - KotlinType initializerType = resolveInitializerType(scope, variable.getInitializer(), dataFlowInfo, trace); - setConstantForVariableIfNeeded(variableDescriptor, scope, variable, dataFlowInfo, initializerType, trace); + KotlinType initializerType = resolveInitializerType(scopeForInitializer, variable.getInitializer(), dataFlowInfo, trace); + setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, initializerType, trace); return initializerType; } } } else { - KotlinType type = typeResolver.resolveType(scope, propertyTypeRef, trace, true); - setConstantForVariableIfNeeded(variableDescriptor, scope, variable, dataFlowInfo, type, trace); + KotlinType type = typeResolver.resolveType(scopeForInitializer, propertyTypeRef, trace, true); + setConstantForVariableIfNeeded(variableDescriptor, scopeForInitializer, variable, dataFlowInfo, type, trace); return type; } } @@ -935,19 +929,19 @@ public class DescriptorResolver { private KotlinType resolveDelegatedPropertyType( @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope scope, + @NotNull LexicalScope scopeForInitializer, @NotNull KtExpression delegateExpression, @NotNull DataFlowInfo dataFlowInfo, @NotNull BindingTrace trace ) { - LexicalScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(propertyDescriptor, scope, trace); KotlinType type = delegatedPropertyResolver.resolveDelegateExpression( - delegateExpression, property, propertyDescriptor, scope, accessorScope, trace, dataFlowInfo); + delegateExpression, property, propertyDescriptor, scopeForInitializer, trace, dataFlowInfo); if (type != null) { + LexicalScope delegateFunctionsScope = JetScopeUtils.makeScopeForDelegateConventionFunctions(scopeForInitializer, propertyDescriptor); KotlinType getterReturnType = delegatedPropertyResolver - .getDelegatedPropertyGetMethodReturnType(propertyDescriptor, delegateExpression, type, trace, accessorScope); + .getDelegatedPropertyGetMethodReturnType(propertyDescriptor, delegateExpression, type, trace, delegateFunctionsScope); if (getterReturnType != null) { return getterReturnType; } @@ -1014,7 +1008,7 @@ public class DescriptorResolver { .toSourceElement(setter)); KtTypeReference returnTypeReference = setter.getReturnTypeReference(); if (returnTypeReference != null) { - KotlinType returnType = typeResolver.resolveType(scope, returnTypeReference, trace, true); + KotlinType returnType = typeResolver.resolveType(scopeWithTypeParameters, returnTypeReference, trace, true); if (!KotlinBuiltIns.isUnit(returnType)) { trace.report(WRONG_SETTER_RETURN_TYPE.on(returnTypeReference)); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java index 5a8e2b8e4e7..7e90627c257 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java @@ -22,12 +22,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.kotlin.descriptors.*; -import org.jetbrains.kotlin.resolve.BindingTrace; -import org.jetbrains.kotlin.resolve.TraceBasedRedeclarationHandler; import org.jetbrains.kotlin.utils.Printer; -import java.util.List; - public final class JetScopeUtils { private JetScopeUtils() {} @@ -42,85 +38,41 @@ public final class JetScopeUtils { }); } - public static LexicalScope makeScopeForPropertyAccessor( - @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope parentScope, - @NotNull BindingTrace trace + public static LexicalScope makeScopeForPropertyHeader( + @NotNull LexicalScope parent, + @NotNull final PropertyDescriptor propertyDescriptor ) { - LexicalScope propertyDeclarationInnerScope = - getPropertyDeclarationInnerScope(propertyDescriptor, parentScope, - propertyDescriptor.getTypeParameters(), - propertyDescriptor.getExtensionReceiverParameter(), trace); - return new LexicalScopeImpl(propertyDeclarationInnerScope, parentScope.getOwnerDescriptor(), false, null, LexicalScopeKind.UNSORTED); - } - - public static LexicalScope getPropertyDeclarationInnerScope( - @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope outerScope, - @NotNull RedeclarationHandler redeclarationHandler - ) { - return getPropertyDeclarationInnerScope(propertyDescriptor, - outerScope, - propertyDescriptor.getTypeParameters(), - propertyDescriptor.getExtensionReceiverParameter(), - redeclarationHandler, - true); - } - - public static LexicalScope getPropertyDeclarationInnerScope( - @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope outerScope, - @NotNull List typeParameters, - @Nullable ReceiverParameterDescriptor receiver, - BindingTrace trace - ) { - return getPropertyDeclarationInnerScope(propertyDescriptor, outerScope, typeParameters, receiver, trace, true); - } - - public static LexicalScope getPropertyDeclarationInnerScopeForInitializer( - @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope outerScope, - @NotNull List typeParameters, - @Nullable ReceiverParameterDescriptor receiver, - BindingTrace trace - ) { - return getPropertyDeclarationInnerScope(propertyDescriptor, outerScope, typeParameters, receiver, trace, false); - } - - private static LexicalScope getPropertyDeclarationInnerScope( - @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope outerScope, - @NotNull List typeParameters, - @Nullable ReceiverParameterDescriptor receiver, - BindingTrace trace, - boolean addLabelForProperty - ) { - TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace); - return getPropertyDeclarationInnerScope(propertyDescriptor, outerScope, typeParameters, receiver, redeclarationHandler, - addLabelForProperty); + return new LexicalScopeImpl(parent, propertyDescriptor, false, null, LexicalScopeKind.PROPERTY_HEADER, + // redeclaration on type parameters should be reported early. see: DescriptorResolver.resolvePropertyDescriptor() + RedeclarationHandler.DO_NOTHING, + new Function1() { + @Override + public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { + for (TypeParameterDescriptor typeParameterDescriptor : propertyDescriptor.getTypeParameters()) { + handler.addClassifierDescriptor(typeParameterDescriptor); + } + return Unit.INSTANCE$; + } + }); } @NotNull - private static LexicalScope getPropertyDeclarationInnerScope( - @NotNull PropertyDescriptor propertyDescriptor, - @NotNull LexicalScope outerScope, - @NotNull final List typeParameters, - @Nullable ReceiverParameterDescriptor receiver, - @NotNull RedeclarationHandler redeclarationHandler, - boolean addLabelForProperty + public static LexicalScope makeScopeForPropertyInitializer( + @NotNull LexicalScope propertyHeader, + @NotNull PropertyDescriptor propertyDescriptor ) { - return new LexicalScopeImpl( - outerScope, propertyDescriptor, addLabelForProperty, receiver, - LexicalScopeKind.UNSORTED, - redeclarationHandler, new Function1() { - @Override - public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { - for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { - handler.addClassifierDescriptor(typeParameterDescriptor); - } - return Unit.INSTANCE$; - } - }); + return new LexicalScopeImpl(propertyHeader, propertyDescriptor, false, null, LexicalScopeKind.PROPERTY_INITIALIZER_OR_DELEGATE); + } + + @NotNull + public static LexicalScope makeScopeForDelegateConventionFunctions( + @NotNull LexicalScope parent, + @NotNull PropertyDescriptor propertyDescriptor + ) { + // todo: very strange scope! + return new LexicalScopeImpl(parent, propertyDescriptor, true, propertyDescriptor.getExtensionReceiverParameter(), + LexicalScopeKind.PROPERTY_DELEGATE_METHOD + ); } @TestOnly diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt index 24862c3dfe1..b437ee40a69 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt @@ -54,8 +54,6 @@ interface LexicalScope: HierarchicalScope { } enum class LexicalScopeKind { - @Deprecated("Temporary") - UNSORTED, EMPTY, CLASS_HEADER, @@ -67,9 +65,9 @@ enum class LexicalScopeKind { CLASS_INITIALIZER, PROPERTY_HEADER, - PROPERTY_INITIALIZER, - PROPERTY_DELEGATE, + PROPERTY_INITIALIZER_OR_DELEGATE, PROPERTY_ACCESSOR, + PROPERTY_DELEGATE_METHOD, FUNCTION_HEADER, FUNCTION_INNER_SCOPE, diff --git a/compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.kt b/compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.kt index 29ffbbce3eb..0c3c305797a 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.kt +++ b/compiler/testData/diagnostics/tests/redeclarations/RedeclaredTypeParameters.kt @@ -2,5 +2,5 @@ fun <T, T> class P<T, T> {} -val <T, T> T.foo : Int +val <T, T> T.foo : Int get() = 1 \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.kt b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.kt index 00b5bcc97aa..f1e1252878c 100644 --- a/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.kt +++ b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.kt @@ -1,10 +1,10 @@ package i -val List.length = size +val List.length = size val List.length1 : Int get() = size -val String.bd = this + "!" +val String.bd = this + "!" val String.bd1 : String get() = this + "!" @@ -13,7 +13,7 @@ class A { val ii : Int = 1 } -val A.foo = ii +val A.foo = ii val A.foo1 : Int get() = ii diff --git a/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.txt b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.txt index feb5db989e2..4ef872f222f 100644 --- a/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.txt +++ b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.txt @@ -2,13 +2,13 @@ package package i { public val i.C.bar: i.C.D - public val kotlin.String.bd: kotlin.String + public val kotlin.String.bd: [ERROR : ] public val kotlin.String.bd1: kotlin.String - public val i.A.foo: kotlin.Int = 1 + public val i.A.foo: [ERROR : Type for ii] public val i.C.foo: i.C.D public val i.A.foo1: kotlin.Int public val i.C.foo1: i.C.D - public val kotlin.List.length: kotlin.Int + public val kotlin.List.length: [ERROR : Type for size] public val kotlin.List.length1: kotlin.Int public final class A { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conventions.dynamic.txt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conventions.dynamic.txt index 955f8a32fae..70c99ca2455 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conventions.dynamic.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/conventions.dynamic.txt @@ -65,8 +65,8 @@ public final fun get(/*0*/ p0: dynamic): dynamic public final fun divAssign(/*0*/ p0: dynamic): dynamic public final fun get(/*0*/ p0: dynamic): dynamic public final fun modAssign(/*0*/ p0: dynamic): dynamic -public fun getValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic -public fun propertyDelegated(/*0*/ p0: dynamic): dynamic -public fun getValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic -public fun setValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic, /*2*/ p2: dynamic): dynamic -public fun propertyDelegated(/*0*/ p0: dynamic): dynamic +public final fun getValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic +public final fun propertyDelegated(/*0*/ p0: dynamic): dynamic +public final fun getValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic +public final fun setValue(/*0*/ p0: dynamic, /*1*/ p1: dynamic, /*2*/ p2: dynamic): dynamic +public final fun propertyDelegated(/*0*/ p0: dynamic): dynamic diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt index 2051760a1a9..a54413083d8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt @@ -167,9 +167,7 @@ public fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: De descriptor, RedeclarationHandler.DO_NOTHING) is PropertyDescriptor -> - JetScopeUtils.getPropertyDeclarationInnerScope(descriptor, - getOuterScope(descriptor, resolutionFacade), - RedeclarationHandler.DO_NOTHING) + JetScopeUtils.makeScopeForPropertyHeader(getOuterScope(descriptor, resolutionFacade), descriptor) is DeclarationDescriptorNonRoot -> getOuterScope(descriptor, resolutionFacade) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt index 17584753df4..9884ca66db5 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt @@ -413,28 +413,19 @@ public class ResolveElementCache( private fun propertyAdditionalResolve(resolveSession: ResolveSession, property: KtProperty, file: KtFile, statementFilter: StatementFilter): BindingTrace { val trace = createDelegatingTrace(property) - val propertyResolutionScope = resolveSession.declarationScopeProvider.getResolutionScopeForDeclaration(property) val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter) val descriptor = resolveSession.resolveToDescriptor(property) as PropertyDescriptor ForceResolveUtil.forceResolveAllContents(descriptor) - val propertyInitializer = property.getInitializer() - if (propertyInitializer != null) { - bodyResolver.resolvePropertyInitializer(DataFlowInfo.EMPTY, property, descriptor, propertyInitializer, propertyResolutionScope) - } - - val propertyDelegate = property.getDelegateExpression() - if (propertyDelegate != null) { - bodyResolver.resolvePropertyDelegate(DataFlowInfo.EMPTY, property, descriptor, propertyDelegate, propertyResolutionScope, propertyResolutionScope) - } - val bodyResolveContext = BodyResolveContextForLazy(TopDownAnalysisMode.LocalDeclarations, { declaration -> - assert(declaration.getParent() == property) { "Must be called only for property accessors, but called for $declaration" } + assert(declaration.getParent() == property || declaration == property) { + "Must be called only for property accessors or for property, but called for $declaration" + } resolveSession.declarationScopeProvider.getResolutionScopeForDeclaration(declaration) }) - bodyResolver.resolvePropertyAccessors(bodyResolveContext, property, descriptor) + bodyResolver.resolveProperty(bodyResolveContext, property, descriptor) forceResolveAnnotationsInside(property) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt index 24a93e7a281..24e7e02c714 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt @@ -259,7 +259,8 @@ object ReplaceWithAnnotationAnalyzer { is PropertyDescriptor -> { val outerScope = getResolutionScope(descriptor.containingDeclaration, ownerDescriptor, additionalScopes) ?: return null - JetScopeUtils.getPropertyDeclarationInnerScope(descriptor, outerScope, RedeclarationHandler.DO_NOTHING) + val propertyHeader = JetScopeUtils.makeScopeForPropertyHeader(outerScope, descriptor) + LexicalScopeImpl(propertyHeader, descriptor, false, descriptor.extensionReceiverParameter, LexicalScopeKind.PROPERTY_ACCESSOR) } else -> return null // something local, should not work with ReplaceWith