diff options
-rw-r--r-- | src/libexpr/primops.cc | 16 | ||||
-rw-r--r-- | tests/lang/eval-okay-attrs2.exp | 1 | ||||
-rw-r--r-- | tests/lang/eval-okay-attrs2.nix | 10 |
3 files changed, 27 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 93a699b41..f08ad0464 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -703,6 +703,20 @@ static Expr primCurrentTime(EvalState & state, const ATermVector & args) } +static Expr primGetAttr(EvalState & state, const ATermVector & args) +{ + string attr = evalString(state, args[0]); + return evalExpr(state, makeSelect(args[1], toATerm(attr))); +} + + +static Expr primHasAttr(EvalState & state, const ATermVector & args) +{ + string attr = evalString(state, args[0]); + return evalExpr(state, makeOpHasAttr(args[1], toATerm(attr))); +} + + static Expr primRemoveAttrs(EvalState & state, const ATermVector & args) { ATermMap attrs(128); /* !!! */ @@ -749,6 +763,8 @@ void EvalState::addPrimOps() addPrimOp("abort", 1, primAbort); addPrimOp("map", 2, primMap); + addPrimOp("__getAttr", 2, primGetAttr); + addPrimOp("__hasAttr", 2, primHasAttr); addPrimOp("removeAttrs", 2, primRemoveAttrs); addPrimOp("relativise", 2, primRelativise); } diff --git a/tests/lang/eval-okay-attrs2.exp b/tests/lang/eval-okay-attrs2.exp new file mode 100644 index 000000000..add36384d --- /dev/null +++ b/tests/lang/eval-okay-attrs2.exp @@ -0,0 +1 @@ +Int(987)
\ No newline at end of file diff --git a/tests/lang/eval-okay-attrs2.nix b/tests/lang/eval-okay-attrs2.nix new file mode 100644 index 000000000..9e06b83ac --- /dev/null +++ b/tests/lang/eval-okay-attrs2.nix @@ -0,0 +1,10 @@ +let { + as = { x = 123; y = 456; } // { z = 789; } // { z = 987; }; + + A = "a"; + Z = "z"; + + body = if builtins.hasAttr A as + then builtins.getAttr A as + else assert builtins.hasAttr Z as; builtins.getAttr Z as; +} |