[Mono-dev] Segfault on base class method access

Paul Melis paul at science.uva.nl
Wed Nov 28 10:47:23 EST 2007


Okay, makes sense (except for the segfault ;-))

In the two-class case (class B, class C:B) using "base" instead of 
"(this as B)"seems to work in C.ToString, so I guess there's special 
handling in place when calling through base?

Paul

Zoltan Varga wrote:

>Hey,
>
>(this as A).ToString () still calls C's ToString () method, so you
>will get infinite recursion and a stack overflow leading to this
>crash.
>
>              Zoltan
>
>On Nov 28, 2007 4:13 PM, Paul Melis <paul at science.uva.nl> wrote:
>  
>
>>Hello,
>>
>>I tried to register at the bug tracker, but did not receive a
>>confirmation mail, so I post here instead.
>>
>>When running the code below mono 1.2.5.2 segfaults. The stack trace is
>>not enlightening.
>>The use case here is to prefix a class's string representation with its
>>base class's string representation.
>>I know about "base", but I figured it only gives you the direct parent
>>and not the parent-of-parent.
>>Btw, if class A is removed (also as base class to B) then this code
>>still segfaults. It seems to be the "this as ..." that's the problem.
>>
>>Regards,
>>Paul
>>
>>
>>using System;
>>
>>class A
>>{
>>    public override string ToString()
>>    {
>>        return "A";
>>    }
>>};
>>
>>class B : A
>>{
>>    public override string ToString()
>>    {
>>        return "B";
>>    }
>>};
>>
>>class C : B
>>{
>>    public override string ToString()
>>    {
>>        return String.Format("({0}) C", (this as A).ToString());
>>    }
>>};
>>
>>class MainClass
>>{
>>    public static void Main(string[] args)
>>    {
>>        C c;
>>
>>        c = new C();
>>        Console.WriteLine("{0}", c);
>>    }
>>}
>>
>>_______________________________________________
>>Mono-devel-list mailing list
>>Mono-devel-list at lists.ximian.com
>>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>>
>>    
>>




More information about the Mono-devel-list mailing list