Skip to content

Commit

Permalink
Merge pull request NixOS#5969 from edolstra/curpos-fix
Browse files Browse the repository at this point in the history
Fix parsing of variable names that are a prefix of '__curPos'
  • Loading branch information
edolstra authored Jan 24, 2022
2 parents 7afbdf2 + bed8270 commit e66550c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/nixexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void ExprConcatStrings::show(std::ostream & str) const
str << "(";
for (auto & i : *es) {
if (first) first = false; else str << " + ";
str << i.second;
str << *i.second;
}
str << ")";
}
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ expr_select

expr_simple
: ID {
if (strncmp($1.p, "__curPos", $1.l) == 0)
std::string_view s = "__curPos";
if (strncmp($1.p, s.data(), s.size()) == 0)
$$ = new ExprPos(CUR_POS);
else
$$ = new ExprVar(CUR_POS, data->symbols.create($1));
Expand Down
1 change: 1 addition & 0 deletions tests/lang/eval-okay-regression-20220122.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions tests/lang/eval-okay-regression-20220122.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
((_: _) 1) + ((__: __) 2)
4 changes: 3 additions & 1 deletion tests/user-envs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ assert foo == "foo";
let

makeDrv = name: progName: (mkDerivation {
inherit name progName system;
name = assert progName != "fail"; name;
inherit progName system;
builder = ./user-envs.builder.sh;
} // {
meta = {
Expand All @@ -26,4 +27,5 @@ in
(makeDrv "foo-2.0" "foo")
(makeDrv "bar-0.1.1" "bar")
(makeDrv "foo-0.1" "foo" // { meta.priority = 10; })
(makeDrv "fail-0.1" "fail")
]

0 comments on commit e66550c

Please sign in to comment.