[Mono-dev] Segfault on base class method access

Paul Melis paul at science.uva.nl
Wed Nov 28 10:13:48 EST 2007


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);
    }
}




More information about the Mono-devel-list mailing list