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

Trim virtual method bodies if they are not called via base and the type itself is not constructed. #2910

Open
teo-tsirpanis opened this issue Jul 21, 2022 · 0 comments

Comments

@teo-tsirpanis
Copy link

teo-tsirpanis commented Jul 21, 2022

Let's say that we have the following code:

using System.Text.RegularExpressions;

Console.WriteLine(new Derived().Get().IsMatch("226"));

public class Base
{
    public virtual Regex Get() => new Regex(@"\d+");
}

public partial class Derived : Base
{
    [RegexGenerator(@"\d+")]
    private static partial Regex GetRegex();

    public override Regex Get() => GetRegex();
}

Base.Get is never called because first, we don't do new Base() anywhere and second, descendants of Base do not call base.Get(). Its method body is preserved however after trimming. The linker could recognize that and trim it away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant