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

cannot instantiate generic object with cast to generic type in template #22645

Closed
arnetheduck opened this issue Sep 5, 2023 · 4 comments · Fixed by #24028
Closed

cannot instantiate generic object with cast to generic type in template #22645

arnetheduck opened this issue Sep 5, 2023 · 4 comments · Fixed by #24028

Comments

@arnetheduck
Copy link
Contributor

Description

type
  Opt[T] = object

  FutureBase* = ref object of RootObj
  Future*[T] = ref object of FutureBase ## Typed future.
    internalValue*: T ## Stored value

template err[T](E: type Opt[T]): E = E()

proc works(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
  var chronosInternalRetFuture: FutureBase
  template result(): untyped {.used.} =
    Future[Opt[int]](chronosInternalRetFuture).internalValue

  result = err(type(result))

proc breaks(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
  var chronosInternalRetFuture: FutureBase
  template result(): untyped {.used.} =
    cast[Future[Opt[int]]](chronosInternalRetFuture).internalValue

  result = err(type(result))

Bonus points for such an excellent compiler error message ;)

Nim Version

1.6.14

Current Output

testit.nim(23, 15) template/generic instantiation of `err` from here
testit.nim(21, 16) Error: cannot instantiate Future [type declared in testit.nim(5, 3)]
got: <T>
but expected: <T>

Expected Output

No response

Possible Solution

No response

Additional Information

No response

@juancarlospaco
Copy link
Collaborator

!nim c

type
  Opt[T] = object

  FutureBase* = ref object of RootObj
  Future*[T] = ref object of FutureBase
    internalValue*: T

template err[T](E: type Opt[T]): E = E()

proc works(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
  var chronosInternalRetFuture: FutureBase
  template result(): untyped {.used.} =
    Future[Opt[int]](chronosInternalRetFuture).internalValue

  result = err(type(result))

proc breaks(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
  var chronosInternalRetFuture: FutureBase
  template result(): untyped {.used.} =
    cast[Future[Opt[int]]](chronosInternalRetFuture).internalValue

  result = err(type(result))

@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

@juancarlospaco (collaborator)

devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(16, 15) template/generic instantiation of `err` from here
/home/runner/work/Nim/Nim/temp.nim(15, 16) Error: cannot instantiate Future [type declared in /home/runner/work/Nim/Nim/temp.nim(4, 3)]
got: <T>
but expected: <T>

Stats

  • Started 2023-09-05T12:40:57
  • Finished 2023-09-05T12:40:58
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
stable 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(16, 15) template/generic instantiation of `err` from here
/home/runner/work/Nim/Nim/temp.nim(15, 16) Error: cannot instantiate Future [type declared in /home/runner/work/Nim/Nim/temp.nim(4, 3)]
got: <T>
but expected: <T>

Stats

  • Started 2023-09-05T12:40:58
  • Finished 2023-09-05T12:40:58
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
2.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(16, 15) template/generic instantiation of `err` from here
/home/runner/work/Nim/Nim/temp.nim(15, 16) Error: cannot instantiate Future [type declared in /home/runner/work/Nim/Nim/temp.nim(4, 3)]
got: <T>
but expected: <T>

Stats

  • Started 2023-09-05T12:40:59
  • Finished 2023-09-05T12:40:59
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
1.6.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(16, 15) template/generic instantiation of `err` from here
/home/runner/work/Nim/Nim/temp.nim(15, 16) Error: cannot instantiate Future [type declared in /home/runner/work/Nim/Nim/temp.nim(4, 3)]
got: <T>
but expected: <T>

Stats

  • Started 2023-09-05T12:41:02
  • Finished 2023-09-05T12:41:03
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
1.4.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(16, 15) template/generic instantiation of `err` from here
/home/runner/work/Nim/Nim/temp.nim(15, 16) Error: cannot instantiate Future
got: <T>
but expected: <T>

Stats

  • Started 2023-09-05T12:41:06
  • Finished 2023-09-05T12:41:06
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
1.2.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(16, 15) template/generic instantiation of `err` from here
/home/runner/work/Nim/Nim/temp.nim(15, 16) Error: cannot instantiate Future
got: <T>
but expected: <T>

Stats

  • Started 2023-09-05T12:41:21
  • Finished 2023-09-05T12:41:21
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
1.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(16, 15) template/generic instantiation of `err` from here
/home/runner/work/Nim/Nim/temp.nim(15, 16) Error: cannot instantiate Future
got: <T>
but expected: <T>

Stats

  • Started 2023-09-05T12:41:34
  • Finished 2023-09-05T12:41:34
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
0.20.2 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(11, 15) Error: expected type, but got: type(Future[Opt[int]](chronosInternalRetFuture).internalValue)()

Stats

  • Started 2023-09-05T12:41:43
  • Finished 2023-09-05T12:41:43
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Opt"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("FutureBase")
      ),
      newEmptyNode(),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          newEmptyNode()
        )
      )
    ),
    nnkTypeDef.newTree(
      nnkPostfix.newTree(
        newIdentNode("*"),
        newIdentNode("Future")
      ),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("T"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("FutureBase")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              nnkPostfix.newTree(
                newIdentNode("*"),
                newIdentNode("internalValue")
              ),
              newIdentNode("T"),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTemplateDef.newTree(
    newIdentNode("err"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("E"),
      nnkIdentDefs.newTree(
        newIdentNode("E"),
        nnkCommand.newTree(
          newIdentNode("type"),
          nnkBracketExpr.newTree(
            newIdentNode("Opt"),
            newIdentNode("T")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkCall.newTree(
        newIdentNode("E")
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("works"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCall.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("breaks"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Future"),
        nnkBracketExpr.newTree(
          newIdentNode("Opt"),
          newIdentNode("int")
        )
      )
    ),
    nnkPragma.newTree(
      nnkExprColonExpr.newTree(
        newIdentNode("stackTrace"),
        newIdentNode("off")
      ),
      newIdentNode("gcsafe"),
      nnkExprColonExpr.newTree(
        newIdentNode("raises"),
        nnkBracket.newTree(
        )
      )
    ),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkVarSection.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("chronosInternalRetFuture"),
          newIdentNode("FutureBase"),
          newEmptyNode()
        )
      ),
      nnkTemplateDef.newTree(
        newIdentNode("result"),
        newEmptyNode(),
        newEmptyNode(),
        nnkFormalParams.newTree(
          newIdentNode("untyped")
        ),
        nnkPragma.newTree(
          newIdentNode("used")
        ),
        newEmptyNode(),
        nnkStmtList.newTree(
          nnkDotExpr.newTree(
            nnkCast.newTree(
              nnkBracketExpr.newTree(
                newIdentNode("Future"),
                nnkBracketExpr.newTree(
                  newIdentNode("Opt"),
                  newIdentNode("int")
                )
              ),
              newIdentNode("chronosInternalRetFuture")
            ),
            newIdentNode("internalValue")
          )
        )
      ),
      nnkAsgn.newTree(
        newIdentNode("result"),
        nnkCall.newTree(
          newIdentNode("err"),
          nnkCall.newTree(
            newIdentNode("type"),
            newIdentNode("result")
          )
        )
      )
    )
  )
)
Stats
  • GCC 11.4.0
  • LibC 2.35
  • Valgrind 3.18.1
  • NodeJS 17.1
  • Linux 5.15.0
  • Created 2023-09-05T12:40:03Z
  • Comments 1
  • Commands nim c --run -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 48 minutes bisecting 8 commits at 0 commits per second.

@metagn
Copy link
Collaborator

metagn commented Sep 5, 2023

Simplified (maybe typedesc/typeof parts can also be factored out):

type
  Opt[T] = object
  Future[T] = object

template err[T](E: typedesc[Future[Opt[T]]]): E = E()

var foo: Future[Opt[int]]

template bar(): untyped =
  cast[Future[Opt[int]]](foo)

discard err type(bar)

Typed AST difference between cast and conversion:

type
  Opt[T] = object
  Future[T] = object

proc err[T](E: typedesc[Future[Opt[T]]]): E = E() # avoid resem, works around bug

var foo: Future[Opt[int]]

template barCast(): untyped =
  cast[Future[Opt[int]]](foo)
  
template barConv(): untyped =
  Future[Opt[int]](foo)

import macros

macro typedTree(x: typed) =
  result = x
  echo x.treeRepr

typedTree:
  discard err type(barCast)
  discard err type(barConv)
StmtList
  DiscardStmt
    Command
      Sym "err"
      TypeOfExpr
        Cast
          Call
            OpenSymChoice 12 "[]"
            Sym "Future"
            Call
              Sym "[]"
              Sym "Opt"
              Sym "int"
          Sym "foo"
  DiscardStmt
    Command
      Sym "err"
      TypeOfExpr
        Conv
          BracketExpr
            Sym "Future"
            BracketExpr
              Sym "Opt"
              Sym "int"
          Sym "foo"

@metagn
Copy link
Collaborator

metagn commented Aug 27, 2024

Seems to work now probably because of #23983

metagn added a commit to metagn/Nim that referenced this issue Aug 29, 2024
@Araq Araq closed this as completed in fc853cb Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants