VB compilation crashes when made of 2 syntax trees with top-level statements
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
Found in https://github.com/dotnet/roslyn/pull/78790
**Steps to Reproduce**:
```vb
Public Sub CrashRepro()
Dim tree1 = SyntaxFactory.ParseSyntaxTree("System.Console.WriteLine(1)", options:=New VisualBasicParseOptions(kind:=SourceCodeKind.Script))
Dim tree2 = SyntaxFactory.ParseSyntaxTree("System.Console.WriteLine(1)", options:=New VisualBasicParseOptions(kind:=SourceCodeKind.Script))
Dim comp = CreateCompilation({tree1, tree2})
Dim semanticModel = comp.GetSemanticModel(tree1)
Dim root1 = DirectCast(tree1.GetRoot(), CompilationUnitSyntax)
Dim exprStatement = DirectCast(root1.Members.First(), ExpressionStatementSyntax)
Dim invocation = DirectCast(exprStatement.Expression, InvocationExpressionSyntax)
Dim memberAccess = DirectCast(invocation.Expression, MemberAccessExpressionSyntax)
Dim symbolInfo = semanticModel.GetSymbolInfo(memberAccess.Name) 'Crashes here
End Sub
```
More specifically, here is the cause:
https://github.com/dotnet/roslyn/blob/30ddabb63d58d3e182770174aae2266b9c8657d4/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb#L2762
There are 2 references in `SyntaxReferences` collection
**Expected behavior:**
Anything other than a crash. In C#, for instance, symbol is correctly resolved, `VerifyDiagnostics()` confirms there are no diagnostics and a constructor of a script class (which is the cause of a crash in VB) has 2 locations to both trees
**Actual behavior:**
Crash
Contributor guide
Assessment
This issue has not been assessed yet.