enthus1ast/nimja

fieldPairs: wrong number of variables

enthus1ast opened this issue · 1 comments

import nimja 

type Model = object
  foo: string
  baa: string

var modelObj = Model(foo: "foo", baa: "baa")
var model = addr modelObj

echo tmpls"""
  {% for (name, val) in fieldPairs(modelObj) %}
    {{name}}
  {% endfor %}
"""

C:\Users\david.choosenim\toolchains\nim-1.6.6\lib\core\macros.nim(540, 5) Error: wrong number of variables

nim c -d:dumpNwtMacro -r ttt.nim

when nimjaTmplsVar`gensym1 is string:
  nimjaTmplsVar`gensym1 = newStringOfCap(11)
nimjaTmplsVar`gensym1 &= "  "
for name, val in    # <--------------- fieldPairs is removed !
  nimjaTmplsVar`gensym1 &= "\n    "
  nimjaTmplsVar`gensym1 &=
      `$` do:
    name
  nimjaTmplsVar`gensym1 &= "\n  ":
  discard
nimjaTmplsVar`gensym1 &= "\n"

But its in the Nimja AST:

[
  {
    "kind": "NStr",
    "strBody": "  "
  },
  {
    "kind": "NFor",
    "forStmt": "name, val in fieldPairs(modelObj)",   # <-------
    "forBody": [
      {
        "kind": "NStr",
        "strBody": "\n    "
      },
      {
        "kind": "NVariable",
        "variableBody": "name"
      },
      {
        "kind": "NStr",
        "strBody": "\n  "
      }
    ]
  },
  {
    "kind": "NStr",
    "strBody": "\n"
  }
]

really strange