Open sbomer opened 2 years ago
The Debug.Assert
is using an interpolation handler:
Assigning to @333fred for triage and investigation. Sounds like a potential CFG issue with interpolation handlers.
As a side note, it may be useful to have an easy-to-copy-and-paste dumper for CFG to assist in such troubleshooting.
That assert is incorrect. Note that IFlowCaptureReference has a IsInitialization
field. If that is true, the assert will fail. Please adjust the assert and let us know if you have any other issues.
Thanks a lot, that's what I was missing! There may still be an issue here:
The repro was simplified down from an assert I initially hit, which was asserting that a written FlowCaptureReference was an l-value flow capture. It seems like the logic in https://github.com/dotnet/roslyn/blob/main/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/FlowAnalysis/LValueFlowCaptureProvider.cs needs to be adjusted to deal with the CFG in this issue - currently it reports that the FlowCaptureReference which initializes the AssertInterpolatedStringHandle
is an r-value flow capture. (Related: https://github.com/dotnet/roslyn/issues/31007)
I've pushed an updated repro to the same branch. Once again, this may just be me missing something - I am working on an analyzer that needs to deal with flow capture references, and copied the relevant logic from Roslyn, but I could be doing something wrong.
Very possibly. @mavasani, can you please take a look at that?
Version Used: 4.3.0-1.22213.10
This didn't repro in 4.0.1 - leave out the
/p:MicrosoftCodeAnalysisVersion=4.3.0-1.22213.10
in the repro script below to see the testcase pass on earlier version 4.0.1 of Microsoft.CodeAnalysis.Steps to Reproduce:
git clone https://github.com/sbomer/linker -b captureRepro --recursive
cd linker
.\repro.ps1
This script just runs a testcase that compiles some code using the specified version of roslyn and runs it through an analyzer:
Test code which triggers analyzer assert:
The following assert in the analyzer is hit:
Expected Behavior: I would have expected that the
Id
of anIFlowCaptureReferenceOperation
in the CFG would have been captured by anIFlowCaptureOperation
in the same CFG. I am hardly familiar with these APIs, so maybe there is some gap in understanding on my part - but this seemed to be the case in older versions from my limited experience.Actual Behavior: There's a flow capture reference to something that was never captured. The CFG has changed between versions of Roslyn - the assert doesn't hit with 4.0.1.
cc @agocke