http://d.puremagic.com/issues/show_bug.cgi?id=2339





------- Comment #1 from matti.niemenmaa+dbugzi...@iki.fi  2009-04-22 03:51 
-------
I've been investigating this a bit and the issue seems to be that
VarDeclaration::needThis() returns true for x; if I make it return false
instead, the code compiles fine. Unfortunately, I can't think of a test that
would cause that and related cases to return false without breaking something
else.

Alternatively, needThis() is correct but some places should be checking for
something else as well.

Here's another testcase, in case it's any help. In this one, it's
FuncDeclaration::needThis() that we don't want returning true.


template ReturnTypeOf(alias f) {
   alias typeof(f()) ReturnTypeOf;
}

template FooIn(char[] s) {
   mixin (
      `template Run() {
         const Run =
            "static if (is(ReturnTypeOf!(mixin(\"`~s~`.foo\")) == void))
               `~s~`.foo;
            else
               static assert (false);
            ";
      }`
   );
}

template Mixin() { void foo() { throw new Exception("Success!"); } }

class C {
   mixin Mixin!() M;

   void runFoo() {
      // Works
      static assert (is(ReturnTypeOf!(M.foo) == void));

      // Fails
      // static assert (is(ReturnTypeOf!(mixin("M.foo")) == void));

      // Fails at an incorrect line number
      // mixin (FooIn!("M").Run!());

      // Fails like the 2nd case above
      // static if (is(ReturnTypeOf!(mixin("M.foo")) == void))
      //    M.foo;
      // else
      //    static assert (false);
   }
}
void main() { (new C).runFoo(); }


I tried returning false from needThis() if scope->parent->isTemplateMixin(),
but that breaks code like this (an LDC testcase):

extern(C) int printf(char*, ...);
template Foo() { void test() { printf("test\n"); typeof(this).whee(); } }
class Bar { void whee() { printf("whee\n"); } mixin Foo!(); }
void main() { (new Bar).test(); }


-- 

Reply via email to