Bug 10573 – Weird linking problem with associative array cast [DMD 2.63]

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2013-07-08T07:08:00Z
Last change time
2013-09-06T22:56:48Z
Keywords
link-failure, pull
Assigned to
nobody
Creator
kozzi11

Comments

Comment #0 by kozzi11 — 2013-07-08T07:08:43Z
With new DMD I have some issue when linking: obj/Debug/TestD.o: In function `_D6object40__T16AssociativeArrayTiTC7handler5mysqlZ16AssociativeArray6rehashMFNdZHiC7handler5mysql': /usr/include/d/druntime/import/object.di:484: undefined reference to `_D26TypeInfo_HiC7handler5mysql6__initZ' With LDMD2 and DMD 2.62 everything seems ok. Problematic code: //---- main.d ----// module main; import handler; void main(string[] args) {} //---- handler.d ----// module handler; abstract class base {} class mysql : base {} class handler { private mysql[int] mysql_servers; public void foo() { base[int] hServers = cast(base[int])mysql_servers; } }
Comment #1 by andrej.mitrovich — 2013-07-08T13:21:36Z
I can recreate this on win32 but only with the -g flag.
Comment #2 by andrej.mitrovich — 2013-07-08T13:56:38Z
Btw, I'd be very careful using casts on hashes like that, there's no runtime checking when you cast hashes, even if the key or value is a base class which is casted to a derived class. For example: ----- class A { } class B : A { void call() { } } void main() { A[int] a; a[1] = new A(); B[int] b = cast(B[int])a; // unsafe, no exceptions thrown b[1].call(); // crash } -----
Comment #3 by kozzi11 — 2013-07-08T23:20:16Z
(In reply to comment #2) > Btw, I'd be very careful using casts on hashes like that, there's no runtime > checking when you cast hashes, even if the key or value is a base class which > is casted to a derived class. For example: > > ----- > class A { } > class B : A { void call() { } } > > void main() > { > A[int] a; > a[1] = new A(); > > B[int] b = cast(B[int])a; // unsafe, no exceptions thrown > b[1].call(); // crash > } > ----- Yes, I realize I can avoid this kind of cast in my case, so now the code is more safe and compilable.
Comment #4 by k.hara.pg — 2013-09-04T05:23:04Z
Comment #5 by github-bugzilla — 2013-09-06T22:56:41Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1a4f809768ac94936299929dff205c8bebb008e5 fix Issue 10573 - Weird linking problem with associative array cast CastExp would call `TypeAArray::getImpl()` in glue layer. However if the AA type is just only used in the cast expression, the timing is too late to invoke `getImpl`, because the AA type instantiation may need more semantic analysis like deferred semantic3. For the correct instantiation of the `AssociativeArray!(K, V)` type, `getImpl` should be invoked in front-end layer beforehand. https://github.com/D-Programming-Language/dmd/commit/b8392c2187e565b1d5c6e1c2ffca4ac527d8c015 Merge pull request #2524 from 9rnsr/fix10573 [REG2.063] Issue 10573 - Weird linking problem with associative array cast