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

Make {.mockable.} useable with generics #2

Open
PhilippMDoerner opened this issue Dec 28, 2022 · 0 comments
Open

Make {.mockable.} useable with generics #2

PhilippMDoerner opened this issue Dec 28, 2022 · 0 comments

Comments

@PhilippMDoerner
Copy link
Owner

PhilippMDoerner commented Dec 28, 2022

This currently breaks:

import std/[genasts, macros]

macro mockable*(p: typed): untyped =
  when defined(mock):
    let
      pName = ident($p[0])
      newName = ident($p[0] & "Base")
      oldPrc = p.copyNimTree

    oldPrc[0] = newName
    result = genast(pName, oldPrc, newName):
      oldPrc
      var pName* = newName
  else:
    result = p


proc toString*[T](x: T): string {.mockable.} = $x
/home/philipp/dev/playground/src/playground.nim(18, 35) template/generic instantiation of `mockable` from here
/usr/lib/nim/std/genasts.nim(87, 13) Error: 'toStringBase' doesn't have a concrete type, due to unspecified generic parameters.
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