Move LexicalScope to frontend
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.kotlin.psi.KtScript;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.expressions.CoercionStrategy;
|
||||
@@ -32,7 +33,6 @@ import java.util.Map;
|
||||
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
|
||||
// SCRIPT: resolve symbols in scripts
|
||||
public class ScriptBodyResolver {
|
||||
|
||||
@@ -54,18 +54,17 @@ public class ScriptBodyResolver {
|
||||
@NotNull
|
||||
public KotlinType resolveScriptReturnType(
|
||||
@NotNull KtScript script,
|
||||
@NotNull ScriptDescriptor scriptDescriptor,
|
||||
@NotNull LexicalScope scopeForBodyResolution,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
// Resolve all contents of the script
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
trace,
|
||||
scriptDescriptor.getScopeForBodyResolution(),
|
||||
DataFlowInfo.EMPTY,
|
||||
NO_EXPECTED_TYPE
|
||||
trace, scopeForBodyResolution, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE
|
||||
);
|
||||
PreliminaryDeclarationVisitor.Companion.createForDeclaration(script, trace);
|
||||
KotlinType returnType = expressionTypingServices.getBlockReturnedType(script.getBlockExpression(), CoercionStrategy.NO_COERCION, context).getType();
|
||||
KotlinType returnType = expressionTypingServices.getBlockReturnedType(
|
||||
script.getBlockExpression(), CoercionStrategy.NO_COERCION, context
|
||||
).getType();
|
||||
if (returnType == null) {
|
||||
returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null");
|
||||
}
|
||||
|
||||
+11
-12
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.resolve.ScriptBodyResolver
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyEntity
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ScriptReceiver
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
@@ -86,22 +85,22 @@ public class LazyScriptDescriptor(
|
||||
)
|
||||
},
|
||||
DeferredType.create(resolveSession.storageManager, resolveSession.trace) {
|
||||
scriptBodyResolver.resolveScriptReturnType(jetScript, this, resolveSession.trace)
|
||||
val scope = LexicalScopeImpl(
|
||||
resolveSession.fileScopeProvider.getFileResolutionScope(jetScript.getContainingJetFile()),
|
||||
this, false, implicitReceiver, "Scope for body resolution for $this"
|
||||
) {
|
||||
for (valueParameterDescriptor in result.valueParameters) {
|
||||
addVariableDescriptor(valueParameterDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
scriptBodyResolver.resolveScriptReturnType(jetScript, scope, resolveSession.trace)
|
||||
}
|
||||
)
|
||||
result
|
||||
}
|
||||
|
||||
override fun getScriptCodeDescriptor() = scriptCodeDescriptor()
|
||||
|
||||
override fun getScopeForBodyResolution(): LexicalScope {
|
||||
return LexicalScopeImpl(resolveSession.fileScopeProvider.getFileResolutionScope(jetScript.getContainingJetFile()),
|
||||
this, false, implicitReceiver, "Scope for body resolution for " + this) {
|
||||
for (valueParameterDescriptor in getScriptCodeDescriptor().valueParameters) {
|
||||
addVariableDescriptor(valueParameterDescriptor)
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun getScriptCodeDescriptor(): ScriptCodeDescriptor = scriptCodeDescriptor()
|
||||
|
||||
override fun forceResolveAllContents() {
|
||||
ForceResolveUtil.forceResolveAllContents(getClassDescriptor())
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
// see ScopeUtils.kt in the frontend module
|
||||
// see utils/ScopeUtils.kt
|
||||
|
||||
interface LexicalScope {
|
||||
val parent: LexicalScope?
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.descriptors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ScriptCodeDescriptor;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
|
||||
public interface ScriptDescriptor extends DeclarationDescriptorNonRoot {
|
||||
String LAST_EXPRESSION_VALUE_FIELD_NAME = "rv";
|
||||
@@ -36,9 +35,6 @@ public interface ScriptDescriptor extends DeclarationDescriptorNonRoot {
|
||||
@NotNull
|
||||
ClassDescriptor getClassDescriptor();
|
||||
|
||||
@NotNull
|
||||
LexicalScope getScopeForBodyResolution();
|
||||
|
||||
@NotNull
|
||||
PropertyDescriptor getScriptResultProperty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user