protected (bool AnalysisSucceded, bool VarAlwaysAssigned) CheckCandidate(StatementSyntax assignmentStatement) { var lcaResult = LowestCommonAncestor.GetCommonAncestorForSyntaxStatements(assignmentStatement, InvocationStatement); var scopedAssignment = lcaResult.ScopedX; var scopedInvocation = lcaResult.ScopedY; if (scopedAssignment == null || scopedInvocation == null) { return(false, false); //If there was some kind of error during analysis we should assume the worst case - that the candidat is valid but not always assigns variable } switch (scopedAssignment) { case SwitchStatementSyntax _: case IfStatementSyntax _: return(true, false); } DataFlowAnalysis flowAnalysisWithAssignment = null; try { flowAnalysisWithAssignment = SemanticModel.AnalyzeDataFlow(scopedAssignment, scopedInvocation); } catch { return(false, false); } if (flowAnalysisWithAssignment == null || !flowAnalysisWithAssignment.Succeeded) { return(false, false); } if (flowAnalysisWithAssignment.AlwaysAssigned.All(var => var.Name != VariableName)) { return(true, false); } return(true, true); }