From f610487f06ac9ec4f924af25736cb4d77d5e593b Mon Sep 17 00:00:00 2001
From: Florian Angerer <florian.angerer@oracle.com>
Date: Tue, 26 Sep 2017 18:56:41 +0200
Subject: [PATCH] Fix: as.call could not handle language.

---
 .../oracle/truffle/r/nodes/builtin/base/AsCall.java    | 10 ++++++++++
 .../truffle/r/test/builtins/TestBuiltin_ascall.java    |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCall.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCall.java
index 5cc9d7e5b4..2bf26e0361 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCall.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/AsCall.java
@@ -32,6 +32,7 @@ import com.oracle.truffle.api.profiles.ConditionProfile;
 import com.oracle.truffle.r.nodes.RASTUtils;
 import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.GetNamesAttributeNode;
 import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
+import com.oracle.truffle.r.nodes.function.RCallBaseNode;
 import com.oracle.truffle.r.runtime.ArgumentsSignature;
 import com.oracle.truffle.r.runtime.RError;
 import com.oracle.truffle.r.runtime.RError.Message;
@@ -87,6 +88,15 @@ public abstract class AsCall extends RBuiltinNode.Arg1 {
         }
     }
 
+    protected boolean containsCall(RLanguage l) {
+        return l.getRep() instanceof RCallBaseNode;
+    }
+
+    @Specialization(guards = "containsCall(l)")
+    protected RLanguage asCall(RLanguage l) {
+        return l;
+    }
+
     @Fallback
     protected Object asCallFunction(@SuppressWarnings("unused") Object x) {
         throw error(RError.Message.GENERIC, "invalid argument list");
diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascall.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascall.java
index 864149114c..7b55239637 100644
--- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascall.java
+++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_ascall.java
@@ -78,5 +78,7 @@ public class TestBuiltin_ascall extends TestBase {
         assertEval(Output.IgnoreWhitespace, "as.call(list(as.symbol('function'), pairlist(a=1)))");
         assertEval(Output.IgnoreWhitespace, "as.call(list(as.symbol('function')))");
         assertEval(Output.IgnoreWhitespace, "call('function')");
+
+        assertEval(Output.IgnoreWhitespace, "{ cl <- quote(fun(3)); as.call(cl) }");
     }
 }
-- 
GitLab