mixin module template -> undefined identifier

Kenji Hara k.hara.pg at gmail.com
Thu Oct 3 19:00:46 PDT 2013


2013/10/4 Robert Schadek <realburner at gmx.de>

> On 10/03/2013 08:10 PM, David Nadlinger wrote:
> > On Thursday, 3 October 2013 at 17:52:13 UTC, Robert Schadek wrote:
> >>
> >> dmd moduleA.d moduleB.d -ofmix -unittest
> >> moduleA.d(4): Error: undefined identifier Foo
> >> moduleB.d(10): Error: template instance A.func!(Foo) error instantiating
> >
> > Yes, this is indeed very much by design – A does not import B, so
> > there is no reason why the name "Foo" should exist in A.
> Yes, it does not exists in the module but func is a template and I was
> under the impression symbols would be seen when instantiated. I mean the
> error starts with A.func!(Foo) error instantiating.
> >
> > To access the template parameter, just use it directly in the mixin
> > (as in »mixin("T.fun()")«). I'm aware that the situation where you
> > actually stumbled over this is probably a bit more complex, but in my
> > experience an equivalent rewrite can almost always be performed quite
> > easily once you have wrapped your head around the concept.
> Not as easy to fix this as I have a library that generates me sqlite
> code at compile time which I than mixin to have as good as handwritten
> code. I just found it odd that it works if I instantiate the template
> from the same module.
>

Using built-in 'stringof' property for code generation won't work in
general. Instead:

public int func(T)() {
    return mixin("T" ~ ".fun()");
}

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20131004/0af7cad2/attachment.html>


More information about the Digitalmars-d mailing list