www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10573] New: Weird linking problem with associative array cast [DMD 2.63]

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10573

           Summary: Weird linking problem with associative array cast [DMD
                    2.63]
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kozzi11 gmail.com


--- Comment #0 from Daniel Kozak <kozzi11 gmail.com> 2013-07-08 07:08:43 PDT ---
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;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 08 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10573


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-07-08
13:21:36 PDT ---
I can recreate this on win32 but only with the -g flag.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10573



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-07-08
13:56:38 PDT ---
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
}
-----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10573



--- Comment #3 from Daniel Kozak <kozzi11 gmail.com> 2013-07-08 23:20:16 PDT ---
(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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10573


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |link-failure, pull


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-09-04 05:23:04 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2524

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 04 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10573



--- Comment #5 from github-bugzilla puremagic.com 2013-09-06 22:56:41 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 06 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10573


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


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