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

Problems with lambdas that capture multiple variables (HAST-286) #89

Open
sarahelsaig opened this issue Nov 15, 2022 · 0 comments
Open
Labels

Comments

@sarahelsaig
Copy link
Member

sarahelsaig commented Nov 15, 2022

When you create a non-static lambda function that captures more than two variables, the decompiler creates seemingly invalid syntax that probably wouldn't compile as C# and the transformed VHDL doesn't compile in v++. This may be an ICSharpCode.Decompiler bug, we can investigate this possibility after we've upgraded to the latest version (see #84).

See an example of the problem here. Originally I tried
tasks[index] = Task.Factory.StartNew(index => ((int)index + step) * heightFactor, index);
but then the decompiled & processed syntax tree would generate display classes with only one field each:

[CompilerGenerated]
private sealed class <>c__DisplayClass7_0
{
    public int heightFactor;
}

[CompilerGenerated]
private sealed class <>c__DisplayClass7_1
{
    public int step;
    public <>c__DisplayClass7_0 CS$<>8__locals1;

    [NullableContext (2)]
    internal int <CreateMatrix>b__0 (int index)
    {
        return (index + this.step) * this.CS$<>8__locals1.heightFactor;
    }
}

Note that this.CS$<>8__locals1.heightFactor; is invalid according to VS Code, Rider and GitHub syntax highlighting. This is the build output log showing the errors according to v++. Besides that, it's also unnecessarily complex to have two nested display classes instead of just one for such a simple mathematical expression. Manually creating the class that contains all values so nothing is captured by the lambda (as I did here) is a valid workaround. In this case the lambda is effectively static so it results in no compiler generated classes.

Jira issue

@github-actions github-actions bot changed the title Problems with lambdas that capture multiple variables Problems with lambdas that capture multiple variables (HAST-286) Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant