Skip to content


[Truffle] Fix regexp errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 12, 2014
1 parent 2df1533 commit 9668c24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class CoreLibrary {
@CompilerDirectives.CompilationFinal private RubyClass rangeClass;
@CompilerDirectives.CompilationFinal private RubyClass rangeErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass regexpClass;
@CompilerDirectives.CompilationFinal private RubyClass regexpErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass rubyTruffleErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass runtimeErrorClass;
@CompilerDirectives.CompilationFinal private RubyClass standardErrorClass;
Expand Down Expand Up @@ -215,6 +216,7 @@ public void initialize() {
rangeClass = new RubyClass(context, objectClass, objectClass, "Range");
rangeErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RangeError");
regexpClass = new RubyRegexp.RubyRegexpClass(context, objectClass);
regexpErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RegexpError");
rubyTruffleErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RubyTruffleError");
runtimeErrorClass = new RubyException.RubyExceptionClass(context, objectClass, standardErrorClass, "RuntimeError");
signalModule = new RubyModule(context, objectClass, "Signal");
Expand Down Expand Up @@ -586,6 +588,11 @@ public RubyException internalError(String message, Node currentNode) {
return new RubyException(context.getCoreLibrary().getRubyTruffleErrorClass(), context.makeString("internal implementation error - " + message), RubyCallStack.getBacktrace(currentNode));

public RubyException regexpError(String message, Node currentNode) {
return new RubyException(regexpErrorClass, context.makeString(message), RubyCallStack.getBacktrace(currentNode));

public RubyContext getContext() {
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.joni.*;
import org.joni.exception.SyntaxException;
import org.joni.exception.ValueException;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyArguments;
Expand Down Expand Up @@ -390,6 +391,8 @@ public static Regex compile(RubyNode currentNode, RubyContext context, byte[] by
return new Regex(bytes, 0, bytes.length, options, encoding, Syntax.RUBY);
} catch (ValueException e) {
throw new org.jruby.truffle.runtime.control.RaiseException(context.getCoreLibrary().runtimeError("error compiling regex", currentNode));
} catch (SyntaxException e) {
throw new org.jruby.truffle.runtime.control.RaiseException(context.getCoreLibrary().regexpError(e.getMessage(), currentNode));

Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/language/regexp/interpolation_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Regexps with interpolation throws RegexpError for malformed interpolation
fails:Regexps with interpolation allows escape sequences in interpolated regexps

0 comments on commit 9668c24

Please sign in to comment.