提交 6b973678 编写于 作者: T Tomáš Matoušek

Merge pull request #3836 from tmat/BadGlobalImports

Avoid translating global imports in presence of declaration errors
......@@ -2203,7 +2203,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Me.EmbeddedSymbolManager.MarkAllDeferredSymbolsAsReferenced(Me)
moduleBeingBuilt.TranslateImports(diagnostics)
' The translation of global imports assumes absence of error symbols.
' We don't need to translate them if there are any declaration errors since
' we are not going to emit the metadata.
If Not hasDeclarationErrors Then
moduleBeingBuilt.TranslateImports(diagnostics)
End If
If moduleBeingBuilt.EmitOptions.EmitMetadataOnly Then
If hasDeclarationErrors Then
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.IO
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Roslyn.Test.Utilities
......@@ -390,5 +391,30 @@ End Class
End Sub)
End Sub
<Fact>
Public Sub BadGlobalImports()
Dim source1 = "
Namespace N
Friend Class A
End Class
End Namespace
"
Dim source2 = "
Class C
Sub Main()
Console.WriteLine()
End Sub
End Class
"
Dim comp1 = CreateCompilationWithMscorlib({source1}, options:=TestOptions.ReleaseDll)
Dim ref1 = comp1.EmitToImageReference()
Dim comp2 = CreateCompilationWithMscorlib(
{source2}, {ref1},
options:=TestOptions.ReleaseDll.WithGlobalImports(GlobalImport.Parse("X=N.A"), GlobalImport.Parse("System")))
comp2.VerifyEmitDiagnostics(
Diagnostic(ERRID.ERR_InaccessibleSymbol2))
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册