Skip to content

Make {.mockable.} useable with generics #2

Description

@PhilippMDoerner

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions