From 0edfea450b90ab5843c1fb898bd9343c881bc4ad Mon Sep 17 00:00:00 2001 From: piegames Date: Sun, 18 Aug 2024 17:28:37 +0200 Subject: [PATCH] libexpr: Soft-deprecate ancient let syntax Change-Id: I6802b26f038578870ea1fa1ed298f0c4b1f29c4a --- doc/manual/rl-next/deprecated-features.md | 1 + src/libexpr/parser/parser.cc | 10 ++++++++++ src/libutil/deprecated-features.cc | 9 +++++++++ src/libutil/deprecated-features.hh | 1 + tests/functional/lang/eval-okay-let.flags | 1 + 5 files changed, 22 insertions(+) create mode 100644 tests/functional/lang/eval-okay-let.flags diff --git a/doc/manual/rl-next/deprecated-features.md b/doc/manual/rl-next/deprecated-features.md index 3f9756fc9..97a660da2 100644 --- a/doc/manual/rl-next/deprecated-features.md +++ b/doc/manual/rl-next/deprecated-features.md @@ -14,3 +14,4 @@ and can be disabled via the flags for backwards compatibility (opt-out with `--e This means that all URLs must be properly put within quotes like all other strings. - `rec-set-overrides`: **__overrides** is an old arcane syntax which has not been in use for more than a decade. It is soft-deprecated with a warning only, with the plan to turn that into an error in a future release. +- `ancient-let`: **The old `let` syntax** (`let { body = …; … }`) is soft-deprecated with a warning as well. Use the regular `let … in` instead. diff --git a/src/libexpr/parser/parser.cc b/src/libexpr/parser/parser.cc index 6e8ab2fe4..17463056c 100644 --- a/src/libexpr/parser/parser.cc +++ b/src/libexpr/parser/parser.cc @@ -668,6 +668,16 @@ template<> struct BuildAST { template<> struct BuildAST : change_head { static void success(const auto & in, BindingsState & b, ExprState & s, State & ps) { + // Added 2024-09-18. Turn into an error at some point in the future. + // See the documentation on deprecated features for more details. + if (!ps.featureSettings.isEnabled(Dep::AncientLet)) + warn( + "%s found at %s. This feature is deprecated and will be removed in the future. Use %s to silence this warning.", + "let {", + ps.positions[ps.at(in)], + "--extra-deprecated-features ancient-let" + ); + b.attrs.pos = ps.at(in); b.attrs.recursive = true; s.pushExpr(b.attrs.pos, b.attrs.pos, std::make_unique(std::move(b.attrs)), ps.s.body); diff --git a/src/libutil/deprecated-features.cc b/src/libutil/deprecated-features.cc index de4efd93b..4de4c8ec7 100644 --- a/src/libutil/deprecated-features.cc +++ b/src/libutil/deprecated-features.cc @@ -36,6 +36,15 @@ constexpr std::array depFeatureDetails Use fix point functions (e.g. `lib.fix` in Nixpkgs) instead. )", }, + { + .tag = Dep::AncientLet, + .name = "ancient-let", + .description = R"( + Allow the ancient `let { body = …; … }` syntax. + + Use the `let … in` syntax instead. + )", + }, { .tag = Dep::UrlLiterals, .name = "url-literals", diff --git a/src/libutil/deprecated-features.hh b/src/libutil/deprecated-features.hh index d4d8a57a9..bdff1bcdb 100644 --- a/src/libutil/deprecated-features.hh +++ b/src/libutil/deprecated-features.hh @@ -19,6 +19,7 @@ namespace nix { enum struct DeprecatedFeature { RecSetOverrides, + AncientLet, UrlLiterals, }; diff --git a/tests/functional/lang/eval-okay-let.flags b/tests/functional/lang/eval-okay-let.flags new file mode 100644 index 000000000..011db98d8 --- /dev/null +++ b/tests/functional/lang/eval-okay-let.flags @@ -0,0 +1 @@ +--extra-deprecated-features ancient-let