Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling virtual methods on derived types binds to the derived method #25

Closed
adrianoc opened this issue Oct 29, 2019 · 1 comment
Closed
Labels
🐛 bug Something isn't working

Comments

@adrianoc
Copy link
Owner

adrianoc commented Oct 29, 2019

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

class D : B
{
    public override void Foo()
    {
    }
}

class D2 : B
{
    public override void Foo()
    {
    }
}

public class C 
{
    void M(B b, D d, D2 d2)
    {
        b.Foo();
        d.Foo(); // Emits:  callvirt instance void D::Foo()
        d2.Foo(); // Emits:  callvirt instance void D::Foo()
    }
}

This happens because the the code that resolves methods finds the Foo() method definition in D and uses it blindly. We need to check whether that method is virtual and lookup the base one in that case.

@adrianoc adrianoc added the 🐛 bug Something isn't working label Oct 29, 2019
@adrianoc
Copy link
Owner Author

Fixed in commit c84d7a4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant