Skip to content

Commit 6318384

Browse files
committed
Address Truffle deprecations
1 parent a59c9d2 commit 6318384

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

doc/contributor/interop.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ exception like
5858
it raises corresponding Ruby exception available in `Truffle::Interop` module.
5959
The names are the same, e.g. `Truffle::Interop::UnsupportedMessageException`.
6060
These exceptions inherit from `Exception`, therefore they are not caught by
61-
default in `rescue` (which catches descendants of `StandardError`). Only `Truffle::Interop::ArityException`takes an
62-
argument, an `Integer` to describe the number of expected arguments.
61+
default in `rescue` (which catches descendants of `StandardError`). Only `Truffle::Interop::ArityException`takes
62+
arguments, two `Integer`s to describe the minimum and maximum number of expected arguments.
6363

6464
The detailed definitions of the behavior can be found in
6565
[another document](interop_details.md).

src/main/java/org/truffleruby/core/exception/CoreExceptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ public RubyException argumentError(int passed, int required, int optional, Node
209209
required + optional), currentNode);
210210
}
211211

212+
@TruffleBoundary
213+
public RubyException argumentErrorMinMaxArity(int passed, int minArity, int maxArity, Node currentNode) {
214+
if (minArity == maxArity) {
215+
return argumentError(passed, minArity, currentNode);
216+
} else if (maxArity < 0) {
217+
return argumentErrorPlus(passed, minArity, currentNode);
218+
} else {
219+
return argumentError(passed, minArity, maxArity - minArity, currentNode);
220+
}
221+
}
222+
212223
public RubyException argumentErrorEmptyVarargs(Node currentNode) {
213224
return argumentError(coreStrings().WRONG_ARGS_ZERO_PLUS_ONE.getRope(), currentNode, null);
214225
}

src/main/java/org/truffleruby/interop/TranslateInteropExceptionNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ protected RuntimeException handle(ArityException exception, boolean inInvokeMemb
125125
@CachedContext(RubyLanguage.class) RubyContext context) {
126126
return new RaiseException(
127127
context,
128-
context.getCoreExceptions().argumentError(
128+
context.getCoreExceptions().argumentErrorMinMaxArity(
129129
exception.getActualArity(),
130-
exception.getExpectedArity(),
130+
exception.getExpectedMinArity(),
131+
exception.getExpectedMaxArity(),
131132
this),
132133
exception);
133134
}

src/main/java/org/truffleruby/interop/TranslateInteropRubyExceptionNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ protected AssertionError arityExceptionClass(
151151
@Cached DispatchNode dispatch,
152152
@Cached IntegerCastNode intCastNode,
153153
@Cached @Shared("logicalClassNode") LogicalClassNode logicalClassNode) throws ArityException {
154-
int expected = intCastNode.executeCastInt(dispatch.call(exception.getException(), "expected"));
155-
throw ArityException.create(expected, arguments.length, exception);
154+
int minExpected = intCastNode.executeCastInt(dispatch.call(exception.getException(), "min_expected"));
155+
int maxExpected = intCastNode.executeCastInt(dispatch.call(exception.getException(), "max_expected"));
156+
throw ArityException.create(minExpected, maxExpected, arguments.length, exception);
156157
}
157158

158159
@Specialization(

src/main/ruby/truffleruby/core/truffle/interop.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ class UnknownIdentifierException < InteropException; end
2323
class UnsupportedTypeException < InteropException; end
2424
class UnknownKeyException < InteropException; end
2525
class ArityException < InteropException
26-
attr_reader :expected
26+
attr_reader :min_expected, :max_expected
2727

28-
def initialize(expected)
29-
@expected = expected
30-
raise ArgumentError unless expected.is_a? Integer
28+
def initialize(min_expected, max_expected = min_expected)
29+
raise ArgumentError unless Primitive.object_kind_of?(min_expected, Integer)
30+
raise ArgumentError unless Primitive.object_kind_of?(max_expected, Integer)
31+
@min_expected = min_expected
32+
@max_expected = max_expected
3133
end
3234
end
3335

0 commit comments

Comments
 (0)