#Bug
CodeCracker throws an exception when building code below.
// The code that reproduces the bug
public class A : IDisposable
{
public void Dispose()
{
GC.SuppressFinalize(this);
}
}
public class B
{
public static B CreateB(A obj)
{
return new B(obj);
}
public B(A obj)
{
Obj = obj;
}
private readonly A Obj;
}
public class Test
{
public async static Task ConfigureSmthAsync()
{
if (!(new C()).IsSmth())
return;
var a = new A();
var b = await Task.Run(() => B.CreateB(a));
}
}
public class C
{
public C() { Variable = true; }
public bool IsSmth() => Variable;
private readonly bool Variable;
}
class Program
{
static void Main()
{
var test = new Test();
Test.ConfigureSmthAsync().Wait();
}
}
Interesting thing that simple change of if() statement removes error.
public class Test
{
public async static Task ConfigureSmthAsync()
{
if ((new C()).IsSmth())
{
var a = new A();
var b = await Task.Run(() => B.CreateB(a));
}
}
}
Don't know if it is important, but error is not appearing when
A is not inherit from IDisposable.
ConfigureSmthAsync is not async.
I managed to get call stack of the error.
System.ArgumentNullException: Value cannot be null.
Parameter name: syntax
at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.CheckSyntaxNode(CSharpSyntaxNode syntax)
at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetSymbolInfo(ExpressionSyntax expression, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.CSharpExtensions.GetSymbolInfo(SemanticModel semanticModel, ExpressionSyntax expression, CancellationToken cancellationToken)
at CodeCracker.CSharp.Usage.DisposableVariableNotDisposedAnalyzer.<>c__DisplayClass12_0.<IsReturned>b__2(ExpressionSyntax returnExpression)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at CodeCracker.CSharp.Usage.DisposableVariableNotDisposedAnalyzer.IsReturned(MethodDeclarationSyntax method, StatementSyntax statement, SemanticModel semanticModel, ILocalSymbol identitySymbol)
at CodeCracker.CSharp.Usage.DisposableVariableNotDisposedAnalyzer.IsDisposedOrAssigned(SemanticModel semanticModel, StatementSyntax statement, ILocalSymbol identitySymbol)
at CodeCracker.CSharp.Usage.DisposableVariableNotDisposedAnalyzer.AnalyzeObjectCreation(SyntaxNodeAnalysisContext context)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__44`1.<ExecuteSyntaxNodeAction>b__44_0(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
I couldn't find similar bug and I am using last release version of the Code Cracker (1.1.0). From NuGet I have only Code Cracker insalled.
#Bug
CodeCracker throws an exception when building code below.
Interesting thing that simple change of
if()statement removes error.Don't know if it is important, but error is not appearing when
Ais not inherit fromIDisposable.ConfigureSmthAsyncis not async.I managed to get call stack of the error.
I couldn't find similar bug and I am using last release version of the Code Cracker (1.1.0). From NuGet I have only Code Cracker insalled.