about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2014-03-09T18·41-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-03-10T09·14+0100
commit049a379ec6ca755bcc077fd0e8da186ff76b8679 (patch)
tree66552a4997d66ce61d87f822d96b8786fe0c62e4
parent908e9ce259710037ae9824a3246143e46e27e867 (diff)
The expr of AttrNames/DynamicAttrDefs is always an ExprConcatStrings
-rw-r--r--src/libexpr/eval.cc8
-rw-r--r--src/libexpr/nixexpr.hh10
-rw-r--r--src/libexpr/parser.y4
3 files changed, 10 insertions, 12 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 730b431cf255..04c3418a0d45 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -642,15 +642,13 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
     /* dynamic attrs apply *after* rec and __overrides */
     foreach (DynamicAttrDefs::iterator, i, dynamicAttrs) {
         Value nameVal;
-        assert(dynamic_cast<ExprConcatStrings *>(i->nameExpr));
-        ExprConcatStrings * nameExpr = static_cast<ExprConcatStrings *>(i->nameExpr);
-        if (nameExpr->es->size() == 1) {
-            nameExpr->es->front()->eval(state, *dynamicEnv, nameVal);
+        if (i->nameExpr->es->size() == 1) {
+            i->nameExpr->es->front()->eval(state, *dynamicEnv, nameVal);
             state.forceValue(nameVal);
             if (nameVal.type == tNull)
                 continue;
         }
-        nameExpr->eval(state, *dynamicEnv, nameVal);
+        i->nameExpr->eval(state, *dynamicEnv, nameVal);
         state.forceStringNoCtx(nameVal);
         Symbol nameSym = state.symbols.create(nameVal.string.s);
         Bindings::iterator j = v.attrs->find(nameSym);
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 7586fffb83d4..a5c5d0533cc9 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -50,16 +50,16 @@ struct Env;
 struct Value;
 class EvalState;
 struct StaticEnv;
-struct Expr;
+struct ExprConcatStrings;
 
 
 /* An attribute path is a sequence of attribute names. */
 struct AttrName
 {
     Symbol symbol;
-    Expr *expr;
+    ExprConcatStrings * expr;
     AttrName(const Symbol & s) : symbol(s) {};
-    AttrName(Expr *e) : expr(e) {};
+    AttrName(ExprConcatStrings * e) : expr(e) {};
 };
 
 typedef std::vector<AttrName> AttrPath;
@@ -174,10 +174,10 @@ struct ExprAttrs : Expr
     typedef std::map<Symbol, AttrDef> AttrDefs;
     AttrDefs attrs;
     struct DynamicAttrDef {
-        Expr * nameExpr;
+        ExprConcatStrings * nameExpr;
         Expr * valueExpr;
         Pos pos;
-        DynamicAttrDef(Expr * nameExpr, Expr * valueExpr, const Pos & pos) : nameExpr(nameExpr), valueExpr(valueExpr), pos(pos) { };
+        DynamicAttrDef(ExprConcatStrings * nameExpr, Expr * valueExpr, const Pos & pos) : nameExpr(nameExpr), valueExpr(valueExpr), pos(pos) { };
     };
     typedef std::vector<DynamicAttrDef> DynamicAttrDefs;
     DynamicAttrDefs dynamicAttrs;
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index dc995db00d59..ab0b862246a0 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -488,7 +488,7 @@ attrpath
           $$->push_back(AttrName(str->s));
           delete str;
       } else
-          $$->push_back(AttrName($3));
+          $$->push_back(AttrName(static_cast<ExprConcatStrings *>($3)));
     }
   | attr { $$ = new vector<AttrName>; $$->push_back(AttrName(data->symbols.create($1))); }
   | string_attr
@@ -498,7 +498,7 @@ attrpath
           $$->push_back(AttrName(str->s));
           delete str;
       } else
-          $$->push_back(AttrName($1));
+          $$->push_back(AttrName(static_cast<ExprConcatStrings *>($1)));
     }
   ;