Skip to content

Commit f3cad5f

Browse files
eregonandrykonchin
authored andcommitted
Raise a SyntaxError if the translator does not know how to deal with a node
* So it can still be caught in user code, e.g. for missing find pattern matching.
1 parent 11d5b57 commit f3cad5f

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/main/java/org/truffleruby/debug/TruffleDebugNodes.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor;
7777
import org.truffleruby.language.arguments.RubyArguments;
7878
import org.truffleruby.language.backtrace.BacktraceFormatter;
79-
import org.truffleruby.language.control.RaiseException;
8079
import org.truffleruby.language.library.RubyStringLibrary;
8180
import org.truffleruby.language.loader.ByteBasedCharSequence;
8281
import org.truffleruby.language.methods.DeclarationContext;
@@ -1461,16 +1460,7 @@ Object parseAndDump(Object code, Object focusedNodeClassName, int index, boolean
14611460
@Cached RubyStringLibrary strings,
14621461
@Cached TruffleString.FromJavaStringNode fromJavaStringNode) {
14631462
String nodeClassNameString = RubyGuards.getJavaString(focusedNodeClassName);
1464-
RubyRootNode rootNode;
1465-
try {
1466-
rootNode = parse(code, mainScript);
1467-
} catch (Error e) {
1468-
if (e.getMessage() != null && e.getMessage().contains("does not know how to translate")) {
1469-
throw new RaiseException(getContext(), coreExceptions().runtimeError(e.getMessage(), this));
1470-
} else {
1471-
throw e;
1472-
}
1473-
}
1463+
RubyRootNode rootNode = parse(code, mainScript);
14741464
String output = TruffleASTPrinter.dump(rootNode, nodeClassNameString, index);
14751465
return createString(fromJavaStringNode, output, Encodings.UTF_8);
14761466
}

src/main/java/org/truffleruby/parser/YARPBaseTranslator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import java.util.List;
1313

14-
import com.oracle.truffle.api.CompilerDirectives;
1514
import org.prism.AbstractNodeVisitor;
1615
import org.prism.Nodes;
1716
import org.truffleruby.RubyLanguage;
@@ -21,6 +20,7 @@
2120
import org.truffleruby.language.RubyContextSourceNode;
2221
import org.truffleruby.language.RubyNode;
2322
import org.truffleruby.language.arguments.NoKeywordArgumentsDescriptor;
23+
import org.truffleruby.language.control.RaiseException;
2424
import org.truffleruby.language.control.SequenceNode;
2525
import org.truffleruby.language.dispatch.RubyCallNodeParameters;
2626
import org.truffleruby.language.literal.NilLiteralNode;
@@ -70,9 +70,9 @@ protected RuntimeException fail(Nodes.Node node) {
7070
var message = this.getClass().getSimpleName() + " does not know how to translate " +
7171
node.getClass().getSimpleName() + " at " + context.fileLine(getSourceSection(node)) +
7272
"\nCode snippet:\n" + code + "\nPrism AST:\n" + node;
73-
// throw new RaiseException(context,
74-
// context.getCoreExceptions().syntaxError(message, null, getSourceSection(node)));
75-
throw CompilerDirectives.shouldNotReachHere(message);
73+
throw new RaiseException(context,
74+
context.getCoreExceptions().syntaxError(message, null, getSourceSection(node)));
75+
// throw CompilerDirectives.shouldNotReachHere(message); // Useful for debugging
7676
}
7777

7878
@Override

0 commit comments

Comments
 (0)