DMD 1.026 and 2.010 releases
Sean Kelly
sean at f4.ca
Tue Jan 22 18:18:37 PST 2008
Walter Bright wrote:
> Extrawurst wrote:
>> ohh what a great day for const, #1319 was in top ten for me ;). thanks
>> for this release!
>>
>> but what happened to scoped interfaces:
>> [CODE]
>>
>> interface IFoo {
>> }
>>
>> class Foo : IFoo {}
>>
>> IFoo getaFoo(){
>> return new Foo();
>> }
>>
>> void main() {
>> scope auto a = getaFoo();
>> }
>>
>> [/CODE]
>>
>> this is illegal since 2.010. how can i do such a thing from now on ?
>
> It never worked anyway. The problem is an interface cannot be deleted.
> The solution is two steps:
>
> scope f = new Foo();
> IFoo i = f;
Why can't an interface be deleted? I'd think the compiler could simply
cast the interface to Object and call _d_delclass on it. Please note
that the suggested workaround isn't always possible, as it's an entirely
legitimate design strategy to have a function return an interface:
interface I { void fn(); }
class C : I { void fn() {} }
class D : I { void fn() {} }
I getAnI() { /* return new C or D */ }
scope i = getAnI(); // shouldn't this be legal?
We currently do this in a number of places within Tango, and I'm
delaying upgrading to DMD 1.026 for now because of this. Worst case, we
can change the code to something like:
auto i = getAnI();
scope(exit) delete cast(Object) i;
But this seems like a silly workaround for something that should work
automatically.
Sean
More information about the Digitalmars-d-announce
mailing list