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

EnC: Updating lambda parameters to discards breaks EnC #48635

Closed
tmat opened this issue Oct 15, 2020 · 1 comment · Fixed by #54856
Closed

EnC: Updating lambda parameters to discards breaks EnC #48635

tmat opened this issue Oct 15, 2020 · 1 comment · Fixed by #54856
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Interactive Bug Interactive-EnC
Milestone

Comments

@tmat
Copy link
Member

tmat commented Oct 15, 2020

Version Used:

Steps to Reproduce:

F5 and update:

class Program
{
    static void Main(string[] args)
    {
        var x = new Func<int, int, int>((a, b) => a + b + 1);
        Console.Write(x(1, 2)); // breakpoint here
    }
}

to

class Program
{
    static void Main(string[] args)
    {
        var x = new Func<int, int, int>((_, _) => 10);
        Console.Write(x(1, 2));
    }
}

Expected Behavior:

The lambda body is matched to the previous one and is updated to return 10. Program prints 10.

Actual Behavior:

The lambdas are not matched, the program prints 2.

See https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/lambda-discard-parameters.md for all forms of discard lambda parameters.

It should also be possible to update discard to named parameter and to change parameter names.

The CLR likely does not support changing IL method parameter names - but we could just ruse the previous names since the method implementing the lambda body is generated and the parameter names do not matter (other than for reflection).

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 15, 2020
@jinujoseph jinujoseph added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 15, 2020
@jinujoseph jinujoseph added this to the 16.9 milestone Oct 15, 2020
@davidwengier davidwengier self-assigned this Jan 12, 2021
@davidwengier davidwengier modified the milestones: 16.9, 16.10 Jan 28, 2021
@davidwengier
Copy link
Contributor

Updated the example, since a single _ parameter is not actually a discard.

Some random thoughts after playing with https://wengier.com/DecompilationDiffer/, I can see how in theory we could allow updating a parameter name to a discard by simple not issuing an edit to the method signature, just the body, and that might work. From experience when I worked on using statements, signatures are still considered when emitting the difference, even without edits, though that might not be true for private classes. Easy enough to verify though.

For going the other way, or if the above doesn't hold, I'm not sure how we can "just use the previous names" as that would mean giving the compiler different trees, which seems odd to me but I haven't looked at how that actually happens so maybe its not as odd as it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Interactive Bug Interactive-EnC
Projects
None yet
4 participants