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

Compiler generated IL overrides wrong method #45337

Closed
gafter opened this issue Jun 20, 2020 · 1 comment
Closed

Compiler generated IL overrides wrong method #45337

gafter opened this issue Jun 20, 2020 · 1 comment
Assignees
Milestone

Comments

@gafter
Copy link
Member

gafter commented Jun 20, 2020

The following program prints "1" instead of "2" as required. That is because the override in Derived is viewed by the runtime as overriding the wrong method (the C# compiler fails to produce the required methodimpl/.override data in the generated assembly).

A similar program with Base.M being abstract generates a type load exception at runtime.

using System;
class Base
{
    public virtual void M(out int x) { x = 1; }
}
abstract class Base2 : Base
{
    public virtual void M(ref int x) { }
}
class Derived : Base2
{
    public override void M(out int x) { x = 3; }
}
class Program
{
    static void Main()
    {
        var b = new Derived();
        b.M(out int x);
        Console.WriteLine(x);
    }
}
@gafter gafter added this to the Compiler.Net5 milestone Jun 20, 2020
@gafter gafter self-assigned this Jun 20, 2020
@gafter gafter added the 4 - In Review A fix for the issue is submitted for review. label Jun 20, 2020
@jaredpar jaredpar modified the milestones: Compiler.Net5, 16.8 Jun 23, 2020
@gafter
Copy link
Member Author

gafter commented Jul 7, 2020

Fixed in #44025

@gafter gafter closed this as completed Jul 7, 2020
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants