http://d.puremagic.com/issues/show_bug.cgi?id=6316

           Summary: Class downcast is rejected in @safe code
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: htven...@gmail.com


--- Comment #0 from Harry Vennik <htven...@gmail.com> 2011-07-14 06:30:27 PDT 
---
The D language specification does not forbid downcasting in @safe code, but the
compiler rejects it. Downcasting is actually safe because such casts are
checked run-time.

The minimal testcase is:

------- CODE -------
class A { }
class B : A { }

@safe void main()
{
    A a = new A();
    B b = cast(B) a;
}
----- END CODE -----


The above code is rejected by the compiler with the following message:
safe_downcast.d(7): Error: cast from safe_downcast.A to safe_downcast.B not
allowed in safe code



Possible enhancement: make DMD issue a warning if the result of a downcast is
not checked for null.

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

Reply via email to