diff options
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/eval.cc | 1 | ||||
-rw-r--r-- | src/libexpr/nixexpr.hh | 2 | ||||
-rw-r--r-- | src/libexpr/parser/parser.cc | 6 | ||||
-rw-r--r-- | src/libexpr/parser/state.hh | 19 |
4 files changed, 27 insertions, 1 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index fcc28d1ca..227cd254a 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -249,6 +249,7 @@ EvalState::EvalState( .findFile = symbols.create("__findFile"), .nixPath = symbols.create("__nixPath"), .body = symbols.create("body"), + .overrides = symbols.create("__overrides"), } , repair(NoRepair) , emptyBindings(0) diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 49e2e4147..52f254813 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -48,7 +48,7 @@ protected: public: struct AstSymbols { - Symbol sub, lessThan, mul, div, or_, findFile, nixPath, body; + Symbol sub, lessThan, mul, div, or_, findFile, nixPath, body, overrides; }; diff --git a/src/libexpr/parser/parser.cc b/src/libexpr/parser/parser.cc index d57c33a30..6e8ab2fe4 100644 --- a/src/libexpr/parser/parser.cc +++ b/src/libexpr/parser/parser.cc @@ -676,6 +676,12 @@ template<> struct BuildAST<grammar::expr::ancient_let> : change_head<BindingsSta template<> struct BuildAST<grammar::expr::rec_set> : change_head<BindingsState> { static void success(const auto & in, BindingsState & b, ExprState & s, State & ps) { + // Before inserting new attrs, check for __override and throw an error + // (the error will initially be a warning to ease migration) + if (!featureSettings.isEnabled(Dep::RecSetOverrides) && b.attrs.attrs.contains(ps.s.overrides)) { + ps.overridesFound(ps.at(in)); + } + b.attrs.pos = ps.at(in); b.attrs.recursive = true; s.pushExpr<ExprAttrs>(b.attrs.pos, std::move(b.attrs)); diff --git a/src/libexpr/parser/state.hh b/src/libexpr/parser/state.hh index 9dddd28e1..1d57e2f5f 100644 --- a/src/libexpr/parser/state.hh +++ b/src/libexpr/parser/state.hh @@ -2,6 +2,7 @@ ///@file #include "eval.hh" +#include "logging.hh" namespace nix::parser { @@ -23,6 +24,7 @@ struct State void dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos); void dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos); + void overridesFound(const PosIdx pos); void addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ptr<Expr> e, const PosIdx pos); std::unique_ptr<Formals> validateFormals(std::unique_ptr<Formals> formals, PosIdx pos = noPos, Symbol arg = {}); std::unique_ptr<Expr> stripIndentation(const PosIdx pos, @@ -58,6 +60,17 @@ inline void State::dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos) }); } +inline void State::overridesFound(const PosIdx pos) { + // Added 2024-09-18. Turn into an error at some point in the future. + // See the documentation on deprecated features for more details. + warn( + "%s found at %s. This feature is deprecated and will be removed in the future. Use %s to silence this warning.", + "__overrides", + positions[pos], + "--extra-deprecated-features rec-set-overrides" + ); +} + inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ptr<Expr> e, const PosIdx pos) { AttrPath::iterator i; @@ -123,6 +136,12 @@ inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ dupAttr(attrPath, pos, j->second.pos); } } else { + // Before inserting new attrs, check for __override and throw an error + // (the error will initially be a warning to ease migration) + if (attrs->recursive && !featureSettings.isEnabled(Dep::RecSetOverrides) && i->symbol == s.overrides) { + overridesFound(pos); + } + // This attr path is not defined. Let's create it. e->setName(i->symbol); attrs->attrs.emplace(std::piecewise_construct, |