Skip to content

Commit a07da0f

Browse files
committed
Handle nested block operations in analyzer
Adds support for analyzing nested block operations in 'get' accessors, improving compatibility with code generated by other tooling. The analyzer now correctly identifies return operations within nested blocks.
1 parent 194d0ff commit a07da0f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/CommunityToolkit.Mvvm.SourceGenerators/Diagnostics/Analyzers/UseObservablePropertyOnSemiAutoPropertyAnalyzer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ public override void Initialize(AnalysisContext context)
148148
// We expect a top-level block operation, that immediately returns an expression
149149
if (context.OperationBlocks is not [IBlockOperation { Operations: [IReturnOperation returnOperation] }])
150150
{
151-
return;
151+
// Special case for nested blocks (e.g. for code generated by some other tooling)
152+
if (context.OperationBlocks is [IBlockOperation { Operations: [IBlockOperation { Operations: [IReturnOperation nestedReturnOperation] }] }])
153+
{
154+
returnOperation = nestedReturnOperation;
155+
}
156+
else
157+
{
158+
// Invalid 'get' accessor structure, we have to stop here
159+
return;
160+
}
152161
}
153162

154163
// Next, we expect the return to produce a field reference

0 commit comments

Comments
 (0)