dotnet / roslyn-analyzers

MIT License
1.6k stars 467 forks source link

CA1845 fix causes a CS8640 error when used in an expression tree #7428

Open Okinodwa opened 1 month ago

Okinodwa commented 1 month ago

Analyzer

Diagnostic ID: CA1845: Use span-based 'string.Concat'

Describe the bug

When concatenating substring calls, CA1845 is triggered. However, when it is triggered inside of an expression tree, the fix for CA1845 (using String.Concat() with .AsSpan()) results in the error: CS8640: Expression tree cannot contain value of ref struct or restricted type.

Expected behavior

I would expect the CA1845 to not trigger in the context of an expression tree.

Actual behavior

The rule is triggered, and results in a complier error when fix is applied.