Skip to content

Call stack overflow with particular inheritance pattern #379

@mattjphillips

Description

@mattjphillips

Came across this problem in 0.8. Consider the following:

public class TestCase
{
    public static void Run()
    {
        Four top = new Four();
        top.Foo();
    }
}

class One
{
    public virtual void Foo() {}
}

class Two : One
{
    public override void Foo()
    {
        base.Foo();
    }
}

class Three : Two
{
}

class Four : Three
{
}

The base.Foo() method in Two.Foo() compiles to:

  ss.base(this, 'foo').call(this);

And in the test case, 'this' is the Four object. However, the logic in ss.base() is such that it returns Two.Foo, so the call() ends up calling itself, resulting in infinite recursion and a call stack overflow.

I've hacked around this in my copy of S# by modifying GenerateMethodExpression to pass the BaseExpression's EvaluatedType.FullGeneratedName as a third parameter to ss.base(), then modifying ss.base() to favor that third parameter as the starting base class in its search for the base method. That's a total stab in the dark, but starting with the base class seems more reasonable than starting with 'this.'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions