I have this macro that seems to work in older versions of Nim. What am I 
missing? Nim complains of `inconsistent typing for reintroduced symbol 
'paramsGlobal' previous type was: object; new type is: object`

MRE below, where the macro creates a new type, then instances that type with 
`var`. My actual macro code is shorter, but using the output of `dumpAstGen` 
reduces possible mistakes.
    
    
    import macros
    macro DefineAndInstance =
      nnkStmtList.newTree(
        nnkTypeSection.newTree(
          nnkTypeDef.newTree(
            nnkPragmaExpr.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("GlobalParams")
              ),
              nnkPragma.newTree(
                newIdentNode("inject")
              )
            ),
            newEmptyNode(),
            nnkObjectTy.newTree(
              newEmptyNode(),
              newEmptyNode(),
              nnkRecList.newTree(
                nnkIdentDefs.newTree(
                  nnkPostfix.newTree(
                    newIdentNode("*"),
                    newIdentNode("prm")
                  ),
                  newIdentNode("float"),
                  newEmptyNode()
                )
              )
            )
          )
        ),
        nnkVarSection.newTree(
          nnkIdentDefs.newTree(
            nnkPragmaExpr.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("paramsGlobal")
              ),
              nnkPragma.newTree(
                newIdentNode("inject")
              )
            ),
            newEmptyNode(),
            nnkObjConstr.newTree(
              newIdentNode("GlobalParams"),
              nnkExprColonExpr.newTree(
                newIdentNode("prm"),
                newLit(0.0)
              )
            )
          )
        )
      )
    expandMacros DefineAndInstance
    
    
    Run

Reply via email to