August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #9 from Sergey Gromov <snake.scaly@gmail.com>  2009-08-14 08:03:44 PDT ---
By the way, the example Lars posted is not as obviously invalid, at least to me.  He passes a local variable as a template alias parameter.  Docs say that "local names" can be used as template alias parameters.  This actually works correctly:

import std.stdio;
void main() {
  foo(1);
}
void foo(int a) {
  bar!(a)();
  writefln(a);
}
void bar(alias var)() {
  var = 2;
}

Prints 2.  This works even if bar is defined in a different module.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962


Jarrett Billingsley <jarrett.billingsley@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley@gmail.c
                   |                            |om




--- Comment #10 from Jarrett Billingsley <jarrett.billingsley@gmail.com>  2009-08-14 08:05:06 PDT ---
(In reply to comment #8)
> Actually I'm not sure if this a bug or an easter egg. The current behaviour of template value parameters is: if it is a compile-time constant, instantiate the template as a value. If it is a variable, instantiate it as an alias parameter.
> 
> That's actually quite cool.

Local variables have been passable as alias parameters for quite some time now.
 :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #11 from Don <clugdbug@yahoo.com.au>  2009-08-14 08:12:03 PDT ---
(In reply to comment #10)
> (In reply to comment #8)
> > Actually I'm not sure if this a bug or an easter egg. The current behaviour of template value parameters is: if it is a compile-time constant, instantiate the template as a value. If it is a variable, instantiate it as an alias parameter.
> > 
> > That's actually quite cool.
> 
> Local variables have been passable as alias parameters for quite some time now.
>  :)

Yes, but if you declare a template parameter as 'alias', it can't accept
literals.
You can actually achieve the same effect with a tuple parameter, so this
behaviour should probably disappear.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #12 from Lars T. Kyllingstad <bugzilla@kyllingen.net>  2009-08-14 12:55:04 PDT ---
What I find very strange here is that when I compile my test case with DMD 2.031 specifying just the four attached files, it works. And it should -- I think the code is valid according to the spec of both D1 and D2.

lars@neutrino:~/tmp/bug2962$ dmd moduleA.d moduleB.d moduleC.d moduleD.d
lars@neutrino:~/tmp/bug2962$ ./moduleA
1

However, when I compile it like rdmd does, specifying every module in Phobos on the command line, it fails:

lars@neutrino:~/tmp/bug2962$ dmd 'moduleA.d' 'moduleC.d'
'/usr/local/include/d/druntime/core/sys/posix/config.d'
'/usr/local/include/d/druntime/core/stdc/stdio.d'
'/usr/local/include/d/druntime/core/sys/posix/fcntl.d' [...]
dmd: glue.c:658: virtual void FuncDeclaration::toObjFile(int): Assertion
`!v->csym' failed.

(Run rdmd with --dry-run to see the full list of files it passes to DMD.)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #13 from Sergey Gromov <snake.scaly@gmail.com>  2009-08-14 13:00:32 PDT ---
(In reply to comment #12)
> What I find very strange here is that when I compile my test case with DMD 2.031 specifying just the four attached files, it works. And it should -- I think the code is valid according to the spec of both D1 and D2.
> 
> lars@neutrino:~/tmp/bug2962$ dmd moduleA.d moduleB.d moduleC.d moduleD.d

Try dmd moduleA.d moduleC.d moduleB.d moduleD.d

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #14 from Lars T. Kyllingstad <bugzilla@kyllingen.net>  2009-08-14 13:05:26 PDT ---
Oh, my. :) Didn't even cross my mind that the order of the files matter.

But my example IS valid code, right?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #15 from Sergey Gromov <snake.scaly@gmail.com>  2009-08-14 13:34:17 PDT ---
I do think it's valid, see my comment #9.  According to the obj2asm, when you pass a local var as an alias parameter to a template:

void foo() {
  int i;
  bar!(i)();
}
void bar(alias var)() {
  var = 1;
}

compiler rewrites it as

void foo() {
  int i;
  void bar() {
    i = 1;
  }
  bar();
}

Probably this rewrite is not always possible, hence the assertion failure.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #16 from Sergey Gromov <snake.scaly@gmail.com>  2009-08-14 14:05:39 PDT ---
Seems like this bug is an ice-on-VALID after all.  All our examples boil down to passing local variables as alias template arguments.  Also it seems like a nice candidate for the issue 340 list.  Don, what do you think?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962





--- Comment #17 from Don <clugdbug@yahoo.com.au>  2009-08-15 11:41:14 PDT ---
(In reply to comment #16)
> Seems like this bug is an ice-on-VALID after all.  All our examples boil down to passing local variables as alias template arguments.  Also it seems like a nice candidate for the issue 340 list.  Don, what do you think?

Could be. I'm busy on other stuff right now, so haven't had a good look at it.
Are you able to simplify the valid code example?
It's worth all bug reporters knowing that the first step to fixing a bug is to
minimize the test case that's in Bugzilla. It helps a _lot_. I found that 90%
of the bugs in bugzilla can be minimized further.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 10, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2962



--- Comment #18 from Don <clugdbug@yahoo.com.au> 2009-09-10 01:29:07 PDT ---
I don't have a patch, but it's easy to at least get the line number into the ICE message.

glue.c line 658:

    if (v->csym)
    error("Bugzilla 2962 - Internal Compiler Error");

Doing this would greatly reduce frustration, and probably allow us to close bug #3283. I'm sure it's a duplicate.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------