From 18a48d80a0686ba81959057e8becc6272acd6c46 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 16 May 2013 19:08:02 +0200 Subject: Show function names in error messages Functions in Nix are anonymous, but if they're assigned to a variable/attribute, we can use the variable/attribute name in error messages, e.g. while evaluating `concatMapStrings' at `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/pkgs/lib/strings.nix:18:25': ... --- src/libexpr/nixexpr.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/libexpr/nixexpr.cc') diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index c52a413916a7..9b75bb644844 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -324,4 +324,24 @@ void ExprConcatStrings::bindVars(const StaticEnv & env) } +/* Storing function names. */ + +void Expr::setName(Symbol & name) +{ +} + + +void ExprLambda::setName(Symbol & name) +{ + this->name = name; + body->setName(name); +} + + +string ExprLambda::showNamePos() +{ + return (format("%1% at %2%") % (name.set() ? "`" + (string) name + "'" : "an anonymous function") % pos).str(); +} + + } -- cgit 1.4.1