properly report exception if analyze failed
#KT-1831 Fixed
This commit is contained in:
@@ -71,6 +71,8 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
return null;
|
||||
}
|
||||
|
||||
exhaust.throwIfError();
|
||||
|
||||
return generate(environment, dependencies, messageCollector, exhaust, stubs);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -96,7 +96,8 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
|
||||
|
||||
injector.getTopDownAnalyzer().analyzeFiles(files);
|
||||
return new AnalyzeExhaust(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
|
||||
|
||||
return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
|
||||
}
|
||||
|
||||
public static AnalyzeExhaust shallowAnalyzeFiles(Collection<JetFile> files,
|
||||
|
||||
@@ -27,12 +27,22 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
public class AnalyzeExhaust {
|
||||
@NotNull
|
||||
private final BindingContext bindingContext;
|
||||
@Nullable
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final Throwable error;
|
||||
|
||||
public AnalyzeExhaust(@NotNull BindingContext bindingContext, @Nullable JetStandardLibrary standardLibrary) {
|
||||
private AnalyzeExhaust(@NotNull BindingContext bindingContext,
|
||||
@Nullable JetStandardLibrary standardLibrary, @Nullable Throwable error) {
|
||||
this.bindingContext = bindingContext;
|
||||
this.standardLibrary = standardLibrary;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public static AnalyzeExhaust success(@NotNull BindingContext bindingContext, @NotNull JetStandardLibrary standardLibrary) {
|
||||
return new AnalyzeExhaust(bindingContext, standardLibrary, null);
|
||||
}
|
||||
|
||||
public static AnalyzeExhaust error(@NotNull BindingContext bindingContext, @NotNull Throwable error) {
|
||||
return new AnalyzeExhaust(bindingContext, null, error);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -40,8 +50,23 @@ public class AnalyzeExhaust {
|
||||
return bindingContext;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NotNull
|
||||
public JetStandardLibrary getStandardLibrary() {
|
||||
return standardLibrary;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Throwable getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return error != null;
|
||||
}
|
||||
|
||||
public void throwIfError() {
|
||||
if (isError()) {
|
||||
throw new IllegalStateException("failed to analyze: " + error, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +165,10 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
||||
// TODO: wrong environment // stepan.koltsov@ 2012-04-09
|
||||
CompilerSpecialMode.REGULAR, CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR));
|
||||
|
||||
if (context.isError()) {
|
||||
throw new IllegalStateException("failed to analyze: " + context.getError(), context.getError());
|
||||
}
|
||||
|
||||
final GenerationState state = new GenerationState(project, builderFactory, context, Collections.singletonList(file)) {
|
||||
@Override
|
||||
protected void generateNamespace(JetFile namespace) {
|
||||
|
||||
@@ -128,6 +128,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
||||
myFile, JetControlFlowDataTraceFactory.EMPTY,
|
||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR));
|
||||
analyzeExhaust.throwIfError();
|
||||
GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile));
|
||||
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||
return state;
|
||||
|
||||
@@ -39,6 +39,7 @@ public class GenerationUtils {
|
||||
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
||||
psiFile, JetControlFlowDataTraceFactory.EMPTY,
|
||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(compilerSpecialMode));
|
||||
analyzeExhaust.throwIfError();
|
||||
GenerationState state = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false), analyzeExhaust, Collections.singletonList(psiFile));
|
||||
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||
return state;
|
||||
|
||||
Reference in New Issue
Block a user