Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fieldPairs: wrong number of variables #86

Open
enthus1ast opened this issue Oct 1, 2022 · 1 comment
Open

fieldPairs: wrong number of variables #86

enthus1ast opened this issue Oct 1, 2022 · 1 comment

Comments

@enthus1ast
Copy link
Owner

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

@enthus1ast
Copy link
Owner Author

enthus1ast commented Aug 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant