Search in sources :

Example 1 with TraceBasedLocalRedeclarationChecker

use of org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker in project kotlin by JetBrains.

the class ExpressionTypingServices method getBlockReturnedType.

@NotNull
public KotlinTypeInfo getBlockReturnedType(@NotNull KtBlockExpression expression, @NotNull CoercionStrategy coercionStrategyForLastExpression, @NotNull ExpressionTypingContext context) {
    List<KtExpression> block = StatementFilterKt.filterStatements(statementFilter, expression);
    DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor();
    TraceBasedLocalRedeclarationChecker redeclarationChecker = new TraceBasedLocalRedeclarationChecker(context.trace, expressionTypingComponents.overloadChecker);
    LexicalWritableScope scope = new LexicalWritableScope(context.scope, containingDescriptor, false, redeclarationChecker, LexicalScopeKind.CODE_BLOCK);
    KotlinTypeInfo r;
    if (block.isEmpty()) {
        r = expressionTypingComponents.dataFlowAnalyzer.createCheckedTypeInfo(expressionTypingComponents.builtIns.getUnitType(), context, expression);
    } else {
        r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context.replaceStatementFilter(statementFilter));
    }
    scope.freeze();
    if (containingDescriptor instanceof ScriptDescriptor) {
        context.trace.record(BindingContext.SCRIPT_SCOPE, (ScriptDescriptor) containingDescriptor, scope);
    }
    return r;
}
Also used : LexicalWritableScope(org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope) TraceBasedLocalRedeclarationChecker(org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor) ScriptDescriptor(org.jetbrains.kotlin.descriptors.ScriptDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 ScriptDescriptor (org.jetbrains.kotlin.descriptors.ScriptDescriptor)1 LexicalWritableScope (org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope)1 TraceBasedLocalRedeclarationChecker (org.jetbrains.kotlin.resolve.scopes.TraceBasedLocalRedeclarationChecker)1