提交 3d4c3912 编写于 作者: A AlekseyTs

RemoveAllSyntaxTrees should preserve embedded syntax trees in Declaration Table.

Fixes #13925.
上级 7f355e7e
......@@ -424,6 +424,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Debug.Assert(syntaxTrees.All(Function(tree) syntaxTrees(syntaxTreeOrdinalMap(tree)) Is tree))
Debug.Assert(syntaxTrees.SetEquals(rootNamespaces.Keys.AsImmutable(), EqualityComparer(Of SyntaxTree).Default))
Debug.Assert(embeddedTrees.All(Function(treeAndDeclaration) declarationTable.Contains(treeAndDeclaration.DeclarationEntry)))
_options = options
_syntaxTrees = syntaxTrees
......@@ -971,7 +972,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return UpdateSyntaxTrees(ImmutableArray(Of SyntaxTree).Empty,
ImmutableDictionary.Create(Of SyntaxTree, Integer)(),
ImmutableDictionary.Create(Of SyntaxTree, DeclarationTableEntry)(),
DeclarationTable.Empty,
AddEmbeddedTrees(DeclarationTable.Empty, _embeddedTrees),
referenceDirectivesChanged:=_declarationTable.ReferenceDirectives.Any())
End Function
......
......@@ -76,6 +76,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End If
End Function
Public Function Contains(rootDeclaration As DeclarationTableEntry) As Boolean
Return rootDeclaration IsNot Nothing AndAlso
(_allOlderRootDeclarations.Contains(rootDeclaration) OrElse _latestLazyRootDeclaration Is rootDeclaration)
End Function
Public Function RemoveRootDeclaration(lazyRootDeclaration As DeclarationTableEntry) As DeclarationTable
' We can only reuse the cache if we're removing the decl that was just added.
If _latestLazyRootDeclaration Is lazyRootDeclaration Then
......
......@@ -1961,5 +1961,52 @@ End Sub
Assert.Throws(Of InvalidOperationException)(Function() CreateSubmission("?a + 1", previous:=s0))
End Sub
<Fact>
<WorkItem(13925, "https://github.com/dotnet/roslyn/issues/13925")>
Public Sub RemoveAllSyntaxTreesAndEmbeddedTrees_01()
Dim compilation1 = CreateCompilationWithMscorlib(
<compilation>
<file name="a.vb">
Public Module C
Sub Main()
System.Console.WriteLine(1)
End Sub
End Module
</file>
</compilation>, options:=TestOptions.ReleaseExe.WithEmbedVbCoreRuntime(True), references:={SystemRef})
compilation1.VerifyDiagnostics()
Dim compilation2 = compilation1.RemoveAllSyntaxTrees()
compilation2 = compilation2.AddSyntaxTrees(compilation1.SyntaxTrees)
compilation2.VerifyDiagnostics()
CompileAndVerify(compilation2, expectedOutput:="1")
End Sub
<Fact>
<WorkItem(13925, "https://github.com/dotnet/roslyn/issues/13925")>
Public Sub RemoveAllSyntaxTreesAndEmbeddedTrees_02()
Dim compilation1 = CreateCompilationWithMscorlibAndVBRuntime(
<compilation>
<file name="a.vb">
Public Module C
Sub Main()
System.Console.WriteLine(1)
End Sub
End Module
</file>
</compilation>, options:=TestOptions.ReleaseExe.WithEmbedVbCoreRuntime(True))
compilation1.VerifyDiagnostics()
Dim compilation2 = compilation1.RemoveAllSyntaxTrees()
compilation2 = compilation2.AddSyntaxTrees(compilation1.SyntaxTrees)
compilation2.VerifyDiagnostics()
CompileAndVerify(compilation2, expectedOutput:="1")
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册