diff options
author | piegames <git@piegames.de> | 2024-08-18 16:02:23 +0200 |
---|---|---|
committer | piegames <git@piegames.de> | 2024-08-21 06:55:52 +0000 |
commit | 7210ed1b87410a0df597c0c4efe642bf82cc2b06 (patch) | |
tree | 85be2a9cc889c74da6a16dd8ca64713f86ce8691 /src/libexpr/parser | |
parent | ac6974777efdaa85715cf7838fe878665061f86c (diff) |
libexpr: Soft-deprecate __overrides
Change-Id: I787e69e1dad6edc5ccdb747b74a9ccd6e8e13bb3
Diffstat (limited to 'src/libexpr/parser')
-rw-r--r-- | src/libexpr/parser/parser.cc | 6 | ||||
-rw-r--r-- | src/libexpr/parser/state.hh | 19 |
2 files changed, 25 insertions, 0 deletions
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, |