Skip to content

Analyzer UNT0038 throws AD0001 caused by exception whe yielded instance has >1 parameters #471

Description

@CortiWins

Bug description

Analyzer UNT0038 throws AD0001

  • Version of analyzers assembly: Microsoft Visual Studio\18\Professional\Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity\Analyzers\Microsoft.Unity.Analyzers.dll Version 18.5.1.0
  • Analyzer rule: UNT0038
  • Error (exception message, type, and callstack where applicable):
Analyzer 'Microsoft.Unity.Analyzers.CacheYieldInstructionAnalyzerAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'Sequence contains more than one matching element'.
Exception occurred with following context:
Compilation: Overdrive.PBPlus.Editor
SyntaxTree: D:\Programme\Installiert\UnityProjects\RetroFPS\Packages\com.overdrive.pbplus\Editor\Scripts\Core\PBPlusModeProvider.cs
SyntaxNode: yield return new A(23, 23); [YieldStatementSyntax]@[329..356) (17,8)-(17,35)

System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.Unity.Analyzers.CacheYieldInstructionAnalyzerAnalyzer.AnalyzeYieldReturn(SyntaxNodeAnalysisContext context)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
-----

Suppress the following diagnostics to disable this analyzer: UNT0038

Code that can cause it:
Happens if ctor has 2 or more parameters. Guess the Unity WaitForSeconds call has one so the analyzer isn't made to deal with more.

public struct A
{
    public A(int a, int b)
    {

    }

    public static IEnumerable<A> GetObjs()
    {
        yield return new A(23, 23); // <- here
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions