@safe matching on subclass type

Nordlöw per.nordlow at gmail.com
Wed Jan 17 13:25:34 UTC 2018


On Wednesday, 17 January 2018 at 13:19:42 UTC, Nordlöw wrote:
> Why isn't polymorphic down-casts such as in the following 
> pattern matching on sub-class
>
> class Base {}
> class Sub : Base {}
>
> @safe unittest
> {
>     auto base = new Base();
>     if (auto sub = cast(Sub)base)
>     {
>         // use sub
>     }
> }
>
> allowed in safe D?

Just discovered that the base instance was const. My mistake...


More information about the Digitalmars-d-learn mailing list