diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index 1a625e59897..eee7a4bdf8c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -41,7 +41,6 @@ import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil; import org.jetbrains.kotlin.resolve.scopes.*; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.types.*; -import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext; import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices; import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor; import org.jetbrains.kotlin.types.expressions.ValueParameterResolver; @@ -636,7 +635,7 @@ public class BodyResolver { assert accessorDeclaringScope != null : "Scope for accessor " + accessor.getText() + " should exists"; LexicalScope headerScope = JetScopeUtils.makeScopeForPropertyHeader(accessorDeclaringScope, descriptor); return new LexicalScopeImpl(headerScope, descriptor, true, descriptor.getExtensionReceiverParameter(), - LexicalScopeKind.PROPERTY_ACCESSOR); + LexicalScopeKind.PROPERTY_ACCESSOR_BODY); } private void resolvePropertyAccessors( @@ -796,7 +795,7 @@ public class BodyResolver { KtProperty property = (KtProperty) function.getParent(); final SyntheticFieldDescriptor fieldDescriptor = new SyntheticFieldDescriptor(accessorDescriptor, property); innerScope = new LexicalScopeImpl(innerScope, functionDescriptor, true, null, - LexicalScopeKind.PROPERTY_ACCESSOR, + LexicalScopeKind.PROPERTY_ACCESSOR_BODY, RedeclarationHandler.DO_NOTHING, new Function1() { @Override public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java index 4963b1f3e6d..4cc97629d1e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.java @@ -103,10 +103,10 @@ public class DelegatedPropertyResolver { @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @NotNull BindingTrace trace, - @NotNull LexicalScope scope + @NotNull LexicalScope delegateFunctionsScope ) { KotlinType returnType = getDelegatedPropertyGetMethodReturnType( - propertyDescriptor, delegateExpression, delegateType, trace, scope); + propertyDescriptor, delegateExpression, delegateType, trace, delegateFunctionsScope); KotlinType propertyType = propertyDescriptor.getType(); /* Do not check return type of get() method of delegate for properties with DeferredType because property type is taken from it */ @@ -123,9 +123,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, false); + resolveDelegatedPropertyConventionMethod(propertyDescriptor, delegateExpression, delegateType, trace, delegateFunctionsScope, false); } @NotNull @@ -138,11 +138,11 @@ public class DelegatedPropertyResolver { @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @NotNull BindingTrace trace, - @NotNull LexicalScope scope + @NotNull LexicalScope delegateFunctionsScope ) { TemporaryBindingTrace traceToResolvePDMethod = TemporaryBindingTrace.create(trace, "Trace to resolve propertyDelegated method in delegated property"); ExpressionTypingContext context = ExpressionTypingContext.newContext( - traceToResolvePDMethod, scope, + traceToResolvePDMethod, delegateFunctionsScope, DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE); KtPsiFactory psiFactory = KtPsiFactory(delegateExpression); @@ -176,7 +176,7 @@ public class DelegatedPropertyResolver { @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @NotNull BindingTrace trace, - @NotNull LexicalScope scope, + @NotNull LexicalScope delegateFunctionsScope, boolean isGet ) { PropertyAccessorDescriptor accessor = isGet ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter(); @@ -185,7 +185,7 @@ public class DelegatedPropertyResolver { if (trace.getBindingContext().get(DELEGATED_PROPERTY_CALL, accessor) != null) return; OverloadResolutionResults functionResults = getDelegatedPropertyConventionMethod( - propertyDescriptor, delegateExpression, delegateType, trace, scope, isGet, true); + propertyDescriptor, delegateExpression, delegateType, trace, delegateFunctionsScope, isGet, true); Call call = trace.getBindingContext().get(DELEGATED_PROPERTY_CALL, accessor); assert call != null : "'getDelegatedPropertyConventionMethod' didn't record a call"; @@ -232,7 +232,7 @@ public class DelegatedPropertyResolver { @NotNull KtExpression delegateExpression, @NotNull KotlinType delegateType, @NotNull BindingTrace trace, - @NotNull LexicalScope scope, + @NotNull LexicalScope delegateFunctionsScope, boolean isGet, boolean isComplete ) { @@ -243,7 +243,7 @@ public class DelegatedPropertyResolver { ? propertyDescriptor.getType() : TypeUtils.NO_EXPECTED_TYPE; ExpressionTypingContext context = ExpressionTypingContext.newContext( - trace, scope, + trace, delegateFunctionsScope, DataFlowInfo.EMPTY, expectedType); boolean hasThis = propertyDescriptor.getExtensionReceiverParameter() != null || propertyDescriptor.getDispatchReceiverParameter() != null; @@ -317,7 +317,7 @@ public class DelegatedPropertyResolver { @NotNull public KotlinType resolveDelegateExpression( @NotNull KtExpression delegateExpression, - @NotNull KtProperty jetProperty, + @NotNull KtProperty property, @NotNull PropertyDescriptor propertyDescriptor, @NotNull LexicalScope scopeForDelegate, @NotNull BindingTrace trace, @@ -326,7 +326,7 @@ public class DelegatedPropertyResolver { TemporaryBindingTrace traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property"); KtExpression calleeExpression = CallUtilKt.getCalleeExpressionIfAny(delegateExpression); ConstraintSystemCompleter completer = createConstraintSystemCompleter( - jetProperty, propertyDescriptor, delegateExpression, scopeForDelegate, trace); + property, propertyDescriptor, delegateExpression, scopeForDelegate, trace); if (calleeExpression != null) { traceToResolveDelegatedProperty.record(CONSTRAINT_SYSTEM_COMPLETER, calleeExpression, completer); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt index b1dd88c8859..74d725f8b20 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/FileScopeProviderImpl.kt @@ -27,15 +27,12 @@ import org.jetbrains.kotlin.resolve.NoSubpackagesInPackageScope import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver import org.jetbrains.kotlin.resolve.TemporaryBindingTrace import org.jetbrains.kotlin.resolve.bindingContextUtil.recordScope -import org.jetbrains.kotlin.resolve.scopes.BaseLexicalScope import org.jetbrains.kotlin.resolve.scopes.ImportingScope import org.jetbrains.kotlin.resolve.scopes.LexicalScope -import org.jetbrains.kotlin.resolve.scopes.LexicalScopeKind import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.resolve.scopes.utils.withParent import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.getValue -import org.jetbrains.kotlin.utils.Printer import org.jetbrains.kotlin.utils.sure public open class FileScopeProviderImpl( @@ -106,14 +103,7 @@ public open class FileScopeProviderImpl( scope = LazyImportScope(scope, aliasImportResolver, LazyImportScope.FilteringKind.ALL, "Alias imports in $debugName") - val lexicalScope = object : BaseLexicalScope(scope, packageFragment) { - override val kind: LexicalScopeKind - get() = LexicalScopeKind.FILE - - override fun printStructure(p: Printer) { - p.println("File top-level scope (empty)") - } - } + val lexicalScope = LexicalScope.empty(scope, packageFragment) bindingTrace.recordScope(lexicalScope, file) 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 7e90627c257..3c3f5925f6f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/JetScopeUtils.java @@ -43,7 +43,7 @@ public final class JetScopeUtils { @NotNull final PropertyDescriptor propertyDescriptor ) { return new LexicalScopeImpl(parent, propertyDescriptor, false, null, LexicalScopeKind.PROPERTY_HEADER, - // redeclaration on type parameters should be reported early. see: DescriptorResolver.resolvePropertyDescriptor() + // redeclaration on type parameters should be reported early, see: DescriptorResolver.resolvePropertyDescriptor() RedeclarationHandler.DO_NOTHING, new Function1() { @Override 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 4c4fb9af1a1..fedcade1b68 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/Scopes.kt @@ -53,7 +53,7 @@ interface LexicalScope: HierarchicalScope { } } -enum class LexicalScopeKind(val local: Boolean) { +enum class LexicalScopeKind(val withLocalDescriptors: Boolean) { EMPTY(false), CLASS_HEADER(false), @@ -67,7 +67,7 @@ enum class LexicalScopeKind(val local: Boolean) { PROPERTY_HEADER(false), PROPERTY_INITIALIZER_OR_DELEGATE(true), - PROPERTY_ACCESSOR(true), + PROPERTY_ACCESSOR_BODY(true), PROPERTY_DELEGATE_METHOD(false), FUNCTION_HEADER(false), @@ -80,13 +80,12 @@ enum class LexicalScopeKind(val local: Boolean) { THEN(true), ELSE(true), - DO_WHILE(true), + DO_WHILE_BODY(true), CATCH(true), FOR(true), - WHILE(true), + WHILE_BODY(true), WHEN(true), - FILE(false), CALLABLE_REFERENCE(false), // for tests, KDoc & IDE diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java index 6938b63a51e..c267a8fc590 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ControlStructureTypingVisitor.java @@ -228,7 +228,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { KotlinTypeInfo bodyTypeInfo; DataFlowInfo conditionInfo = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(condition, true, context).and(dataFlowInfo); if (body != null) { - LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, LexicalScopeKind.WHILE); + LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, LexicalScopeKind.WHILE_BODY); bodyTypeInfo = components.expressionTypingServices.getBlockReturnedTypeWithWritableScope( scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo)); @@ -321,7 +321,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { bodyTypeInfo = facade.getTypeInfo(body, context.replaceScope(context.scope)); } else if (body != null) { - LexicalWritableScope writableScope = newWritableScopeImpl(context, LexicalScopeKind.DO_WHILE); + LexicalWritableScope writableScope = newWritableScopeImpl(context, LexicalScopeKind.DO_WHILE_BODY); conditionScope = writableScope; List block; if (body instanceof KtBlockExpression) { 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 24e7e02c714..fc1b39a6430 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt @@ -260,7 +260,7 @@ object ReplaceWithAnnotationAnalyzer { is PropertyDescriptor -> { val outerScope = getResolutionScope(descriptor.containingDeclaration, ownerDescriptor, additionalScopes) ?: return null val propertyHeader = JetScopeUtils.makeScopeForPropertyHeader(outerScope, descriptor) - LexicalScopeImpl(propertyHeader, descriptor, false, descriptor.extensionReceiverParameter, LexicalScopeKind.PROPERTY_ACCESSOR) + LexicalScopeImpl(propertyHeader, descriptor, false, descriptor.extensionReceiverParameter, LexicalScopeKind.PROPERTY_ACCESSOR_BODY) } else -> return null // something local, should not work with ReplaceWith