DMD 1.026 and 2.010 releases

Lars Ivar Igesund larsivar at igesund.net
Thu Jan 24 06:57:41 PST 2008


Sean Kelly wrote:

> 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:

Considering there is code in Tango that does not compile with 1.026 due to
this, code that compiled and worked with previous versions, this is an
obvious regression and breakage in the stable compiler branch.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango


More information about the Digitalmars-d-announce mailing list