---- test.d
import traits;
void formatValue()() { string[char] aa; aa.length; }
void main() { formatValue(); }
---- traits.d
enum LOOKUP_LINKAGE =
[
'F': "D",
'U': "C",
'W': "Windows",
'V': "Pascal",
'R': "C++"
];
--- command line
dmd test.d
--- output
OPTLINK (R) for Win32 Release 8.00.7
Copyright (C) Digital Mars 1989-2010 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test.obj(test)
Error 42: Symbol Undefined _D6object28__T16AssociativeArrayTaTAyaZ16AssociativeArray6lengthMFNdZk
--- errorlevel 1
Comment #1 by issues.dlang — 2011-09-29T16:11:26Z
Yeah. I've been seeing various errors related to undefined symbols when using enums with AAs with the latest compiler, but I haven't been able to reduce them like this.
Comment #2 by k.hara.pg — 2011-09-30T07:25:02Z
This is not only the problem of AA, it is where template instantiation is belongs to.
---- test.d
import traits;
void func()(){ X!() x; auto n = x.length; }
void main(){ func(); assert(0); }
---- traits.d
struct X(){ int length(){ return 0; } }
enum x = X!()();
---- command line
dmd test.d
---- output
OPTLINK (R) for Win32 Release 8.00.7
Copyright (C) Digital Mars 1989-2010 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
test2.obj(test2)
Error 42: Symbol Undefined _D6traits6__T1XZ1X6lengthMFZi
semantic() runs against the type of X!() at both line 2 in test and line 2 of traits, but its instantiation belongs to only traits, because the semantic runs first in traits.
But the module traits never generate .obj, then the symbol ob X!().length will be lost.
Comment #3 by braddr — 2011-10-23T14:28:53Z
What version of dmd ever built this code successfully?
Comment #4 by issues.dlang — 2011-10-23T14:49:08Z
I have code with a similar error which compiled with 2.054 (or at least between the release of 2.054 and 2.055 - it compiled before, but it won't compile with 2.054 because it requires Phobos changes since 2.054 and it fails with 2.055 thanks to the compiler erroring out), but if this didn't compile with 2.054, then it's probably not quite the same bug, and I was premature in labeling it a regression. Unfortunately, I've failed to narrow down my code to a reasonable example for a bug report, so it's hard to be 100% certain that this is the same bug.
Comment #5 by braddr — 2011-10-23T14:55:10Z
I tried several points in time back to Jan 2010. None of them built the example code. Without a known working version, it's not a regression. Lowering to critical.
If you have code which went from working to not working and is valid code, please add it to this report or file a new one.
Comment #6 by issues.dlang — 2011-10-23T17:03:03Z
Well, I'm definitely confused. I finally managed to reduce my code to a reasonably test case, but I can't find a version of the compiler where it worked. So, I don't know what happened. My test case is pretty similar to Kenji's though, so I expect that it's the same bug.
a.d
---
import b;
void main()
{
}
b.d
---
import std.exception;
enum E {a, b, c}
immutable int[E] aa;
shared static this()
{
int[E] temp;
temp[E.a] = 1;
temp[E.b] = 2;
temp[E.c] = 3;
aa = assumeUnique(temp);
}
a.o: In function `_D6object30__T16AssociativeArrayTE1b1ETiZ16AssociativeArray6rehashMFNdZHE1b1Ei':
b.d:(.text._D6object30__T16AssociativeArrayTE1b1ETiZ16AssociativeArray6rehashMFNdZHE1b1Ei+0x37): undefined reference to `_D16TypeInfo_HE1b1Ei6__initZ'
a.o: In function `_D6object31__T16AssociativeArrayTE1b1ETyiZ16AssociativeArray6rehashMFNdZHE1b1Eyi':
b.d:(.text._D6object31__T16AssociativeArrayTE1b1ETyiZ16AssociativeArray6rehashMFNdZHE1b1Eyi+0x37): undefined reference to `_D17TypeInfo_HE1b1Eyi6__initZ'
collect2: ld returned 1 exit status
--- errorlevel 1
Comment #7 by govellius — 2012-07-10T09:45:07Z
void main()
{
enum E { a=1, b=2 }
// Fail at link
// undefined reference to `_Dmain1E6__initZ'
E[ string ] fail1 = [ "a":E.a, "b":E.b ];
string[ E ] fail2 = [ E.a:"a", E.b:"b" ];
// Works
enum { c=3, d=4 }
auto works1 = [ "c":c , "d":d ];
auto works2 = [ c:"c", d:"d" ];
}
---
Bug does not happen if "enum E" is moved out of main to module scope.
Comment #8 by k.hara.pg — 2013-02-17T05:37:30Z
(In reply to comment #0)
> ---- test.d
> import traits;
> void formatValue()() { string[char] aa; aa.length; }
> void main() { formatValue(); }
>
> ---- traits.d
> enum LOOKUP_LINKAGE =
> [
> 'F': "D",
> 'U': "C",
> 'W': "Windows",
> 'V': "Pascal",
> 'R': "C++"
> ];
Now, the case in comment #0 is a dup of bug 8997, but more general case in comment #1 isn't.
Comment #9 by k.hara.pg — 2013-02-17T05:44:04Z
(In reply to comment #8)
> Now, the case in comment #0 is a dup of bug 8997, but more general case in
> comment #1 isn't.
s/comment #1/comment #2/
Comment #10 by k.hara.pg — 2015-09-07T15:26:50Z
(In reply to Kenji Hara from comment #2)
> This is not only the problem of AA, it is where template instantiation is
> belongs to.
>
> ---- test.d
> import traits;
> void func()(){ X!() x; auto n = x.length; }
> void main(){ func(); assert(0); }
>
> ---- traits.d
> struct X(){ int length(){ return 0; } }
> enum x = X!()();
>
> ---- command line
> dmd test.d
>
> ---- output
> OPTLINK (R) for Win32 Release 8.00.7
> Copyright (C) Digital Mars 1989-2010 All rights reserved.
> http://www.digitalmars.com/ctg/optlink.html
> test2.obj(test2)
> Error 42: Symbol Undefined _D6traits6__T1XZ1X6lengthMFZi
>
> semantic() runs against the type of X!() at both line 2 in test and line 2
> of traits, but its instantiation belongs to only traits, because the
> semantic runs first in traits.
> But the module traits never generate .obj, then the symbol ob X!().length
> will be lost.
Now, the question has been resolved.
Since 2.064, new template instantiation strategy has been introduced:
https://github.com/D-Programming-Language/dmd/pull/2550
By that, when a template X!() is instantiated in both root module (test.d) and non-root module (traits.d), it's assumed that the instantiated code would exist in the linked object file of the non-root module.
But the command line `dmd test.d` does not correctly compile & link the traits.d module.
Then test.obj fail to link the instantiated X!().length() funciton.
In short, the link-failure is intentional behavior.
Close this issue as "resolved".