From 93326d8643b002b5eeb4e2adf8840efdd38df615 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 23 Dec 2014 17:52:29 +0300 Subject: [PATCH] Added centralized positioning for front-end exceptions --- .../ExpressionTypingVisitorDispatcher.java | 65 ++++++++++++------- .../jet/utils/KotlinFrontEndException.kt | 19 ++++++ 2 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 compiler/util/src/org/jetbrains/jet/utils/KotlinFrontEndException.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorDispatcher.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorDispatcher.java index 06e531092cd..fc27bafcba6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorDispatcher.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingVisitorDispatcher.java @@ -16,8 +16,10 @@ package org.jetbrains.jet.lang.types.expressions; +import com.intellij.openapi.progress.ProcessCanceledException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; @@ -26,6 +28,7 @@ import org.jetbrains.jet.lang.types.DeferredType; import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.JetTypeInfo; import org.jetbrains.jet.util.ReenteringLazyValueComputationException; +import org.jetbrains.jet.utils.KotlinFrontEndException; import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM; import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo; @@ -123,35 +126,49 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor visitor) { - JetTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext()); - if (recordedTypeInfo != null) { - return recordedTypeInfo; - } - JetTypeInfo result; try { - result = expression.accept(visitor, context); - // Some recursive definitions (object expressions) must put their types in the cache manually: - if (context.trace.get(BindingContext.PROCESSED, expression)) { - return JetTypeInfo.create(context.trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression), - result.getDataFlowInfo()); - } - - if (result.getType() instanceof DeferredType) { - result = JetTypeInfo.create(((DeferredType) result.getType()).getDelegate(), result.getDataFlowInfo()); - } - if (result.getType() != null) { - context.trace.record(BindingContext.EXPRESSION_TYPE, expression, result.getType()); + JetTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext()); + if (recordedTypeInfo != null) { + return recordedTypeInfo; + } + JetTypeInfo result; + try { + result = expression.accept(visitor, context); + // Some recursive definitions (object expressions) must put their types in the cache manually: + if (context.trace.get(BindingContext.PROCESSED, expression)) { + return JetTypeInfo.create(context.trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression), + result.getDataFlowInfo()); + } + + if (result.getType() instanceof DeferredType) { + result = JetTypeInfo.create(((DeferredType) result.getType()).getDelegate(), result.getDataFlowInfo()); + } + if (result.getType() != null) { + context.trace.record(BindingContext.EXPRESSION_TYPE, expression, result.getType()); + } + + } + catch (ReenteringLazyValueComputationException e) { + context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression)); + result = JetTypeInfo.create(null, context.dataFlowInfo); } + context.trace.record(BindingContext.PROCESSED, expression); + recordScopeAndDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression); + return result; } - catch (ReenteringLazyValueComputationException e) { - context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression)); - result = JetTypeInfo.create(null, context.dataFlowInfo); + catch (ProcessCanceledException e) { + throw e; + } + catch (KotlinFrontEndException e) { + throw e; + } + catch (Throwable e) { + throw new KotlinFrontEndException( + "Exception while analyzing expression at " + DiagnosticUtils.atLocation(expression) + ":\n" + expression.getText() + "\n", + e + ); } - - context.trace.record(BindingContext.PROCESSED, expression); - recordScopeAndDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression); - return result; } ////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/compiler/util/src/org/jetbrains/jet/utils/KotlinFrontEndException.kt b/compiler/util/src/org/jetbrains/jet/utils/KotlinFrontEndException.kt new file mode 100644 index 00000000000..f361fee95a4 --- /dev/null +++ b/compiler/util/src/org/jetbrains/jet/utils/KotlinFrontEndException.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.utils + +public class KotlinFrontEndException(message: String, cause: Throwable) : RuntimeException(message, cause) \ No newline at end of file