Skip to content
Snippets Groups Projects
Commit 9911d03f authored by Tomas Stupka's avatar Tomas Stupka
Browse files

changed error msg when accessing attributes for a foreign object

parent ef25c411
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.r.nodes.attributes.GetAttributeNode;
......@@ -48,6 +49,7 @@ import com.oracle.truffle.r.runtime.builtins.RBuiltin;
import com.oracle.truffle.r.runtime.data.RAttributable;
import com.oracle.truffle.r.runtime.data.RAttributesLayout;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RList;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RNull;
import com.oracle.truffle.r.runtime.data.model.RAbstractContainer;
......@@ -136,6 +138,8 @@ public abstract class Attr extends RBuiltinNode.Arg3 {
protected Object attr(Object object, Object name, Object exact) {
if (object instanceof RAttributable) {
return attrRA((RAttributable) object, intern.execute((String) name), (boolean) exact);
} else if (RRuntime.isForeignObject(object)) {
throw RError.error(this, Message.OBJ_CANNOT_BE_ATTRIBUTED);
} else {
throw RError.nyi(this, "object cannot be attributed");
}
......
......@@ -84,7 +84,7 @@ public abstract class Attributes extends RBuiltinNode.Arg1 {
} else {
return createResult((RAttributable) object, false);
}
} else if (object == RNull.instance) {
} else if (object == RNull.instance || RRuntime.isForeignObject(object)) {
return RNull.instance;
} else {
throw RError.nyi(this, "object cannot be attributed");
......
......@@ -32,6 +32,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.r.nodes.attributes.RemoveAttributeNode;
import com.oracle.truffle.r.nodes.attributes.SetAttributeNode;
......@@ -47,6 +48,7 @@ import com.oracle.truffle.r.nodes.unary.CastToVectorNode;
import com.oracle.truffle.r.nodes.unary.CastToVectorNodeGen;
import com.oracle.truffle.r.nodes.unary.GetNonSharedNode;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RError.Message;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.Utils;
import com.oracle.truffle.r.runtime.builtins.RBuiltin;
......@@ -243,6 +245,8 @@ public abstract class UpdateAttr extends RBuiltinNode.Arg3 {
attributable.setAttr(internedName, value);
}
return object;
} else if (RRuntime.isForeignObject(obj)) {
throw RError.error(this, Message.OBJ_CANNOT_BE_ATTRIBUTED);
} else {
throw RError.nyi(this, "object cannot be attributed");
}
......
......@@ -613,6 +613,7 @@ public final class RError extends RuntimeException {
INVALID_FORMAT_LOGICAL("invalid format '%s'; use format %%d or %%i for logical objects"),
INVALID_FORMAT_INTEGER("invalid format '%s'; use format %%d, %%i, %%o, %%x or %%X for integer objects"),
POS_NOT_ALLOWED_WITH_NUMERIC("pos argument not allowed with a numeric value"),
OBJ_CANNOT_BE_ATTRIBUTED("external object cannot be attributed"),
// the following list is incomplete (but like GNU-R)
INVALID_FORMAT_DOUBLE("invalid format '%s'; use format %%f, %%e, %%g or %%a for numeric objects"),
INVALID_LOGICAL("'%s' must be TRUE or FALSE"),
......
......@@ -339,6 +339,13 @@ public class TestJavaInterop extends TestBase {
assertEvalFastR("tc <- .fastr.java.class('" + TestNamesClassMap.class.getName() + "'); t <- .fastr.interop.new(tc); sort(names(t$m()))", "c('one', 'two')");
}
@Test
public void testAttributes() {
assertEvalFastR("to <- .fastr.interop.new(.fastr.java.class('" + TEST_CLASS + "')); attributes(to)", "NULL");
assertEvalFastR("to <- .fastr.interop.new(.fastr.java.class('" + TEST_CLASS + "')); attr(to, 'a')<-'a'", "cat('Error in attr(to, \"a\") <- \"a\" : external object cannot be attributed\n')");
assertEvalFastR("to <- .fastr.interop.new(.fastr.java.class('" + TEST_CLASS + "')); attr(to, which = 'a')", "cat('Error in attr(to, which = \"a\") : external object cannot be attributed\n')");
}
private String getRValue(Object value) {
if (value == null) {
return "NULL";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment