Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn abnormal CompilerError into regular Panic #7651

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package org.enso.interpreter.node;

import java.util.function.Supplier;

import org.enso.compiler.core.CompilerError;
import org.enso.interpreter.EnsoLanguage;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.data.text.Text;
import org.enso.interpreter.runtime.error.PanicException;
import org.enso.interpreter.runtime.scope.LocalScope;
import org.enso.interpreter.runtime.scope.ModuleScope;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.source.SourceSection;
import java.util.function.Supplier;
import org.enso.interpreter.EnsoLanguage;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.scope.LocalScope;
import org.enso.interpreter.runtime.scope.ModuleScope;

@ReportPolymorphism
@NodeInfo(shortName = "Method", description = "A root node for Enso methods.")
Expand Down Expand Up @@ -142,9 +148,16 @@ public Object executeGeneric(VirtualFrame frame) {

@CompilerDirectives.TruffleBoundary
final ExpressionNode replaceItself() {
try {
ExpressionNode newNode = replace(provider.get());
notifyInserted(newNode);
return newNode;
} catch (CompilerError abnormalException) {
var ctx = EnsoContext.get(this);
var msg = Text.create(abnormalException.getMessage());
var load = ctx.getBuiltins().error().makeCompileError(msg);
throw new PanicException(load, this);
}
}
}
public boolean isSubjectToInstrumentation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.OutputStream;
import java.nio.file.Paths;

import org.enso.polyglot.RuntimeOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
Expand Down Expand Up @@ -100,6 +101,24 @@ public void testRecursiveDefinition() throws Exception {
assertTrue("The error value also represents null", error.isNull());
assertEquals("(Error: Uninitialized value)", error.toString());
}
@Test
public void dotUnderscore() throws Exception {
var module = ctx.eval("enso", """
run op =
op._
""");
var run = module.invokeMember("eval_expression", "run");
try {
var error = run.execute("false_hope");
fail("Should never return, but: " + error);
} catch (PolyglotException e) {
assertTrue("It is exception", e.getGuestObject().isException());
assertEquals("Panic", e.getGuestObject().getMetaObject().getMetaSimpleName());
if (!e.getMessage().contains("Compiler Internal Error")) {
fail("Expecting Compiler Internal Error, but was: " + e.getMessage());
}
}
}

@Test
public void testInvalidEnsoProjectRef() throws Exception {
Expand Down