Bug 1038 – explicit class cast breakage in 1.007

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-03-08T04:54:00Z
Last change time
2014-02-16T15:25:53Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
default_357-line

Comments

Comment #0 by default_357-line — 2007-03-08T04:54:53Z
Consider the following code: import std.stdio; class A { } class B : A { } void main() { A test=new B; writefln("Test is ", test.toString); A test_2=cast(A)(new B); writefln("Test 2 is ", test_2.toString); } What we would expect to see is "test7.B" twice. However, what we see is "test7.B" and "test7.A", which of course completely breaks polymorphism. The error doesn't appear on 1.005, so it was introduced either in '006 or '007. Greetings --downs
Comment #1 by fvbommel — 2007-03-08T05:20:14Z
Judging by the disassembled code, it appears "cast(A)(new B)"is compiled as if it was "new A", it passes the ClassInfo for A instead of that for B to _d_newclass... By the way, the same thing happens in GDC[1], so it's most likely an error in the front-end. [1]: (gdc 0.23, using dmd 1.007), the x86-64 Linux binary from sourceforge.
Comment #2 by thomas-dloop — 2007-03-11T06:20:27Z
Comment #3 by thomas-dloop — 2007-03-12T01:23:42Z
Fixed in DMD-1.009