dotnet/roslyn

Remove extraneous branch for empty strings in interpolated string handler CFG

Open

#57,611 opened on Nov 5, 2021

 (0 comments) (0 reactions) (1 assignee)C# (4,257 forks)batch import
Area-CompilersBugFeature - IOperationFeature - Interpolated String Improvementshelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

When an interpolated string handler is created for an empty string, and the constructor of the handler uses an out bool success parameter, we generate an unnecessary branch in the CFG for the code, demonstrated in the InterpolatedStringHandlerConversionFlow_16 test. We could take the approach Aleksey detailed in his review to remove that branch, but we will have to wire a CreateDiscardSymbol method through the semantic model to be able to create an IDiscardOperation for the parameter value. This is presently undone.

Contributor guide