Skip to content

Support with expression precedence - #4340

Open
siegfriedpammer wants to merge 1 commit into
masterfrom
fix/with-expression-precedence
Open

siegfriedpammer wants to merge 1 commit into
masterfrom
fix/with-expression-precedence

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

Fixes #4338.

With expressions consume switch expressions in the C# grammar, so they need their own precedence level below switch expressions. This also ensures a with expression is parenthesized when used as a member or invocation target.

Tests: dotnet test --project ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj --report-trx --filter FullyQualifiedName~InsertParenthesesVisitorTests.WithExpressionAsMemberReferenceTarget

With expressions are below switch expressions in the C# grammar and must be parenthesized before member access.

Assisted-by: OpenCode:gpt-5.6-luna:OpenCode

public override void VisitWithInitializerExpression(WithInitializerExpression withInitializerExpression)
{
ParenthesizeIfRequired(withInitializerExpression.Expression, PrecedenceLevel.Switch + 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch+1 ?
There's no test case for a complex expression in the context of with.
Also check nesting: a with {} with {}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

With statements on instances get incorrectly decompiled

2 participants