Fixed scope kind for default values

This commit is contained in:
Stanislav Erokhin
2015-11-09 13:40:19 +03:00
parent a502405779
commit ebc3ccbb2a
3 changed files with 42 additions and 43 deletions
@@ -563,7 +563,7 @@ public class BodyResolver {
final ConstructorDescriptor unsubstitutedPrimaryConstructor final ConstructorDescriptor unsubstitutedPrimaryConstructor
) { ) {
return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null, return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null,
LexicalScopeKind.PRIMARY_CONSTRUCTOR_DEFAULT_VALUE, RedeclarationHandler.DO_NOTHING, LexicalScopeKind.DEFAULT_VALUE, RedeclarationHandler.DO_NOTHING,
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() { new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override @Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) { public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
@@ -787,9 +787,7 @@ public class BodyResolver {
List<ValueParameterDescriptor> valueParameterDescriptors = functionDescriptor.getValueParameters(); List<ValueParameterDescriptor> valueParameterDescriptors = functionDescriptor.getValueParameters();
valueParameterResolver.resolveValueParameters( valueParameterResolver.resolveValueParameters(
valueParameters, valueParameterDescriptors, valueParameters, valueParameterDescriptors, innerScope, outerDataFlowInfo, trace, callChecker
ExpressionTypingContext.newContext(
trace, innerScope, outerDataFlowInfo, NO_EXPECTED_TYPE, callChecker)
); );
// Synthetic "field" creation // Synthetic "field" creation
@@ -53,43 +53,44 @@ interface LexicalScope: HierarchicalScope {
} }
} }
enum class LexicalScopeKind { enum class LexicalScopeKind(val local: Boolean) {
EMPTY, EMPTY(false),
CLASS_HEADER, CLASS_HEADER(false),
CLASS_INHERITANCE, CLASS_INHERITANCE(false),
CONSTRUCTOR_HEADER, CONSTRUCTOR_HEADER(false),
PRIMARY_CONSTRUCTOR_DEFAULT_VALUE, CLASS_STATIC_SCOPE(false),
CLASS_STATIC_SCOPE, CLASS_MEMBER_SCOPE(false),
CLASS_MEMBER_SCOPE, CLASS_INITIALIZER(true),
CLASS_INITIALIZER,
PROPERTY_HEADER, DEFAULT_VALUE(true),
PROPERTY_INITIALIZER_OR_DELEGATE,
PROPERTY_ACCESSOR,
PROPERTY_DELEGATE_METHOD,
FUNCTION_HEADER, PROPERTY_HEADER(false),
FUNCTION_INNER_SCOPE, PROPERTY_INITIALIZER_OR_DELEGATE(true),
PROPERTY_ACCESSOR(true),
PROPERTY_DELEGATE_METHOD(false),
CODE_BLOCK, FUNCTION_HEADER(false),
FUNCTION_INNER_SCOPE(true),
LEFT_BOOLEAN_EXPRESSION, CODE_BLOCK(true),
RIGHT_BOOLEAN_EXPRESSION,
THEN, LEFT_BOOLEAN_EXPRESSION(true),
ELSE, RIGHT_BOOLEAN_EXPRESSION(true),
DO_WHILE,
CATCH,
FOR,
WHILE,
WHEN,
FILE, THEN(true),
CALLABLE_REFERENCE, ELSE(true),
DO_WHILE(true),
CATCH(true),
FOR(true),
WHILE(true),
WHEN(true),
FILE(false),
CALLABLE_REFERENCE(false),
// for tests, KDoc & IDE // for tests, KDoc & IDE
SYNTHETIC SYNTHETIC(false)
} }
interface ImportingScope : HierarchicalScope { interface ImportingScope : HierarchicalScope {
@@ -22,36 +22,36 @@ import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DescriptorResolver import org.jetbrains.kotlin.resolve.DescriptorResolver
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.scopes.LexicalScope 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.types.TypeUtils import org.jetbrains.kotlin.types.TypeUtils
public class ValueParameterResolver( public class ValueParameterResolver(
private val expressionTypingServices: ExpressionTypingServices, private val expressionTypingServices: ExpressionTypingServices,
private val constantExpressionEvaluator: ConstantExpressionEvaluator private val constantExpressionEvaluator: ConstantExpressionEvaluator
) { ) {
@JvmOverloads
public fun resolveValueParameters( public fun resolveValueParameters(
valueParameters: List<KtParameter>, valueParameters: List<KtParameter>,
valueParameterDescriptors: List<ValueParameterDescriptor>, valueParameterDescriptors: List<ValueParameterDescriptor>,
declaringScope: LexicalScope, declaringScope: LexicalScope,
dataFlowInfo: DataFlowInfo, dataFlowInfo: DataFlowInfo,
trace: BindingTrace trace: BindingTrace,
callChecker: CallChecker = CallChecker.DoNothing
) { ) {
resolveValueParameters(valueParameters, valueParameterDescriptors, val scopeForDefaultValue = LexicalScopeImpl(declaringScope, declaringScope.ownerDescriptor, false, null, LexicalScopeKind.DEFAULT_VALUE)
ExpressionTypingContext.newContext(trace, declaringScope, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE)
) val contextForDefaultValue = ExpressionTypingContext.newContext(trace, scopeForDefaultValue, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE, callChecker)
}
public fun resolveValueParameters(
valueParameters: List<KtParameter>,
valueParameterDescriptors: List<ValueParameterDescriptor>,
context: ExpressionTypingContext
) {
for ((descriptor, parameter) in valueParameterDescriptors zip valueParameters) { for ((descriptor, parameter) in valueParameterDescriptors zip valueParameters) {
ForceResolveUtil.forceResolveAllContents(descriptor.getAnnotations()) ForceResolveUtil.forceResolveAllContents(descriptor.getAnnotations())
resolveDefaultValue(descriptor, parameter, context) resolveDefaultValue(descriptor, parameter, contextForDefaultValue)
} }
} }