1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 02:11:15 +02:00

Print value on type error

Adds the failing value to `value is <TYPE> while a <TYPE> is expected`
error messages.
This commit is contained in:
Rebecca Turner 2023-12-06 16:03:01 -08:00
parent b74ec56da9
commit cb7fbd4d83
No known key found for this signature in database
19 changed files with 227 additions and 136 deletions

View file

@ -9,11 +9,13 @@
#include <iostream>
#include "eval.hh"
#include "print-options.hh"
namespace nix {
class EvalState;
struct Value;
/**
* Print a string as a Nix string literal.
*
@ -59,4 +61,21 @@ std::ostream & printIdentifier(std::ostream & o, std::string_view s);
void printValue(EvalState & state, std::ostream & str, Value & v, PrintOptions options = PrintOptions {});
/**
* A partially-applied form of `printValue` which can be formatted using `<<`
* without allocating an intermediate string.
*/
class ValuePrinter {
friend std::ostream & operator << (std::ostream & output, const ValuePrinter & printer);
private:
EvalState & state;
Value & value;
PrintOptions options;
public:
ValuePrinter(EvalState & state, Value & value, PrintOptions options = PrintOptions {})
: state(state), value(value), options(options) { }
};
std::ostream & operator<<(std::ostream & output, const ValuePrinter & printer);
}