dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.95k stars 4.02k forks source link

ExceptionUtilities.UnexpectedValue in VisualBasicOperationFactory for BoundKind.TypeArguments #35813

Open mavasani opened 5 years ago

mavasani commented 5 years ago
  1. Build \src\Tools\AnalyzerRunner\AnalyzerRunner.csproj (you might have to manually apply the work around in https://github.com/dotnet/roslyn/issues/35812 before building)
  2. cd $(RepoRoot)\artifacts\bin\AnalyzerRunner\Release\net472
  3. Execute AnalyzerRunner.exe . $(RepoRoot)\Compilers.sln /concurrent

Exception thrown in VisualBasicOperationFactory here for unhandled BoundKind.TypeArguments

    Microsoft.CodeAnalysis.dll!Roslyn.Utilities.ExceptionUtilities.UnexpectedValue(object o) Line 18    C#
>   Microsoft.CodeAnalysis.VisualBasic.dll!Microsoft.CodeAnalysis.Operations.VisualBasicOperationFactory.CreateInternal(Microsoft.CodeAnalysis.VisualBasic.BoundNode boundNode) Line 348    Basic
    mscorlib.dll!System.Collections.Concurrent.ConcurrentDictionary<Microsoft.CodeAnalysis.VisualBasic.BoundNode, Microsoft.CodeAnalysis.IOperation>.GetOrAdd(Microsoft.CodeAnalysis.VisualBasic.BoundNode key, System.Func<Microsoft.CodeAnalysis.VisualBasic.BoundNode, Microsoft.CodeAnalysis.IOperation> valueFactory)  Unknown
    Microsoft.CodeAnalysis.VisualBasic.dll!Microsoft.CodeAnalysis.Operations.VisualBasicOperationFactory.Create(Microsoft.CodeAnalysis.VisualBasic.BoundNode boundNode) Line 84 Basic
    Microsoft.CodeAnalysis.VisualBasic.dll!Microsoft.CodeAnalysis.Operations.VisualBasicOperationFactory.CreateFromArray(Of Microsoft.CodeAnalysis.VisualBasic.BoundNode, Microsoft.CodeAnalysis.IOperation)(System.Collections.Immutable.ImmutableArray(Of Microsoft.CodeAnalysis.VisualBasic.BoundNode) nodeArray) Line 90    Basic
    Microsoft.CodeAnalysis.VisualBasic.dll!Microsoft.CodeAnalysis.Operations.VisualBasicLazyInvalidOperation.CreateChildren() Line 536  Basic
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Operations.LazyInvalidOperation.Children.get() Line 3768  C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Operations.OperationExtensions.Descendants(Microsoft.CodeAnalysis.IOperation operation, bool includeSelf) Line 99 C#
    System.Collections.Immutable.dll!System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.IOperation>.Builder.AddRange(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.IOperation> items)   Unknown
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.PooledObjects.ArrayBuilder<Microsoft.CodeAnalysis.IOperation>.AddRange(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.IOperation> items) Line 471  C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver<Microsoft.CodeAnalysis.VisualBasic.SyntaxKind>.GetOperationsToAnalyze(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.IOperation> operationBlocks) Line 2176    C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver<Microsoft.CodeAnalysis.VisualBasic.SyntaxKind>.TryExecuteDeclaringReferenceActions.__getOperationsToAnalyzeWithStackGuard|4(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.IOperation> operationBlocksToAnalyze) Line 1949 C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver<Microsoft.CodeAnalysis.VisualBasic.SyntaxKind>.TryExecuteDeclaringReferenceActions.__executeExecutableCodeActions|3() Line 1928    C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver<Microsoft.CodeAnalysis.VisualBasic.SyntaxKind>.TryExecuteDeclaringReferenceActions(Microsoft.CodeAnalysis.SyntaxReference decl, int declarationIndex, Microsoft.CodeAnalysis.Diagnostics.SymbolDeclaredCompilationEvent symbolEvent, Microsoft.CodeAnalysis.Diagnostics.AnalysisScope analysisScope, Microsoft.CodeAnalysis.Diagnostics.AnalysisState analysisStateOpt, Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver<Microsoft.CodeAnalysis.VisualBasic.SyntaxKind>.GroupedAnalyzerActions additionalPerSymbolActions, bool shouldExecuteSyntaxNodeActions, bool shouldExecuteOperationActions, bool shouldExecuteCodeBlockActions, bool shouldExecuteOperationBlockActions, bool isInGeneratedCode, System.Threading.CancellationToken cancellationToken) Line 1851  C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver<Microsoft.CodeAnalysis.VisualBasic.SyntaxKind>.TryExecuteDeclaringReferenceActions(Microsoft.CodeAnalysis.Diagnostics.SymbolDeclaredCompilationEvent symbolEvent, Microsoft.CodeAnalysis.Diagnostics.AnalysisScope analysisScope, Microsoft.CodeAnalysis.Diagnostics.AnalysisState analysisStateOpt, bool isGeneratedCodeSymbol, Microsoft.CodeAnalysis.Diagnostics.AnalyzerActions additionalPerSymbolActionsOpt, System.Threading.CancellationToken cancellationToken) Line 1739 C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver.TryProcessSymbolDeclaredAsync(Microsoft.CodeAnalysis.Diagnostics.SymbolDeclaredCompilationEvent symbolEvent, Microsoft.CodeAnalysis.Diagnostics.AnalysisScope analysisScope, Microsoft.CodeAnalysis.Diagnostics.AnalysisState analysisStateOpt, System.Threading.CancellationToken cancellationToken) Line 1060    C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver.TryProcessEventCoreAsync(Microsoft.CodeAnalysis.Diagnostics.CompilationEvent e, Microsoft.CodeAnalysis.Diagnostics.AnalysisScope analysisScope, Microsoft.CodeAnalysis.Diagnostics.AnalysisState analysisStateOpt, System.Threading.CancellationToken cancellationToken) Line 1001 C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver.ProcessEventAsync(Microsoft.CodeAnalysis.Diagnostics.CompilationEvent e, Microsoft.CodeAnalysis.Diagnostics.AnalysisScope analysisScope, Microsoft.CodeAnalysis.Diagnostics.AnalysisState analysisStateOpt, System.Threading.CancellationToken cancellationToken) Line 935 C#
    Microsoft.CodeAnalysis.dll!Microsoft.CodeAnalysis.Diagnostics.AnalyzerDriver.ProcessCompilationEventsCoreAsync(Microsoft.CodeAnalysis.Diagnostics.AnalysisScope analysisScope, Microsoft.CodeAnalysis.Diagnostics.AnalysisState analysisStateOpt, bool prePopulatedEventQueue, System.Threading.CancellationToken cancellationToken) Line 922   C#
mavasani commented 5 years ago

Tagging @333fred @AlekseyTs

AlekseyTs commented 5 years ago

@mavasani Is this a regression? Do you have any idea what have changed?

mavasani commented 5 years ago

@AlekseyTs I am not sure if this a regression. However, I have been able to run all IDE analyzers on entire Roslyn.sln in past using the same AnalyzerRunner tool/steps above. So it seems likely that it is a regression, but I can't be 100% sure.

AlekseyTs commented 5 years ago

Since you have a repro, could you narrow it down to a stand alone unit-test?

mavasani commented 5 years ago

@AlekseyTs

        <CompilerTrait(CompilerFeature.IOperation)>
        <Fact>
        Public Sub TestBoundTypeArgument()
            Dim source = <![CDATA[
Option Strict On
Imports System.Runtime.CompilerServices

Class A
End Class

Class Derived1
    Inherits A
End Class

Class Derived2
    Inherits A
End Class

Class C
    Public Function M(node As Object) As A
        Return If(node.ExtensionMethod(Of Derived1), DirectCast(node.ExtensionMethod(Of Derived2)(), A)) 'BIND:"Return If(node.ExtensionMethod(Of Derived1), DirectCast(node.ExtensionMethod(Of Derived2)(), A))"
    End Function
End Class
]]>.Value

            ' TODO: Baseline to be generated
            Dim expectedOperationTree = <![CDATA[
]]>.Value

            Dim expectedDiagnostics = String.Empty

            VerifyOperationTreeAndDiagnosticsForTest(Of ReturnStatementSyntax)(source, expectedOperationTree, expectedDiagnostics)
        End Sub
mavasani commented 5 years ago

@AlekseyTs @333fred - By the way, to reproduce this I attempted to locally run the compiler unit tests with ROSLYN_TEST_IOPERATION=true, and I see large of asserts and exceptions in the unit tests, most of them seem to be related to nullable types, symbol with annotations, etc.

@333fred - anything blocking https://github.com/dotnet/roslyn/pull/31724 to enable the new test leg for this?

333fred commented 5 years ago

@mavasani mainly that enabling the hook on all tests was causing timeouts for the leg.