Crash in out contract in interface

Timon Gehr timon.gehr at gmx.ch
Wed Aug 24 06:35:05 PDT 2011


On 08/24/2011 03:13 PM, Alex Rønne Petersen wrote:
> Hi,
>
> This is an odd one. Consider the following code:
>
>> interface I
>> {
>> void foo()
>> out { assert(bar()); }
>> bool bar();
>> }
>>
>> class C : I
>> {
>> void foo() {}
>> bool bar() { return true; }
>> }
>>
>> void main()
>> {
>> C c = new C();
>> c.foo();
>> }
>
> This will crash and burn when run:
>
>> object.Error: Access Violation
>> ----------------
>> 40DB64
>> 40D9DB
>> 402050
>> 402074
>> 4026F3
>> 4022EF
>> 4127B5
>> ----------------
>
> I assume this is a bug, but has anyone encountered this before or have
> any idea why exactly it happens when calling other interface methods in
> an interface method's out contract? (It seems to work fine in the in
> contract.)
>
> - Alex

I think it actually makes a lot of sense. I.foo's out contract assumes 
an I this reference, but C.foo passes a C this reference without 
adjustment. What I don't quite get yet is what is the matter with in 
contracts on interface member functions. Not only do they not crash, 
apparently they are not even executed.

Have you already filed a bug report?







More information about the Digitalmars-d mailing list