about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLinus Heckemann <git@sphalerite.org>2019-03-21T13·32+0100
committerLinus Heckemann <git@sphalerite.org>2019-03-21T14·31+0100
commit2aa89daab3a8351a03f6d57d3e1f737cccd59850 (patch)
treeeac2bcaff33d4db1b9306a8d76ffa11de0e8b0a5
parent6a3dfcb623b82d62e090cd023144454bd1a15d91 (diff)
eval: improve type description for primops and applied primops
This can make type errors a little easier to understand.
-rw-r--r--src/libexpr/eval.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 2a194d0e08c9..211f7a55f737 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -130,6 +130,16 @@ std::ostream & operator << (std::ostream & str, const Value & v)
 }
 
 
+const Value *getPrimOp(const Value &v) {
+    const Value * primOp = &v;
+    while (primOp->type == tPrimOpApp) {
+        primOp = primOp->primOpApp.left;
+    }
+    assert(primOp->type == tPrimOp);
+    return primOp;
+}
+
+
 string showType(const Value & v)
 {
     switch (v.type) {
@@ -144,8 +154,10 @@ string showType(const Value & v)
         case tApp: return "a function application";
         case tLambda: return "a function";
         case tBlackhole: return "a black hole";
-        case tPrimOp: return "a built-in function";
-        case tPrimOpApp: return "a partially applied built-in function";
+        case tPrimOp:
+            return fmt("the built-in function '%s'", string(v.primOp->name));
+        case tPrimOpApp:
+            return fmt("the partially applied built-in function '%s'", string(getPrimOp(v)->primOp->name));
         case tExternal: return v.external->showType();
         case tFloat: return "a float";
     }