未验证 提交 2ef73778 编写于 作者: M Manish Vasani 提交者: GitHub

Merge pull request #30368 from mavasani/Issue30309

Fix symbol end action not completing for symbols with non-implicit me…
......@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.Diagnostics
......@@ -170,7 +169,7 @@ void processMembers(IEnumerable<ISymbol> members)
{
foreach (var member in members)
{
if (!member.IsImplicitlyDeclared)
if (!member.IsImplicitlyDeclared && member.IsInSource())
{
memberSet = memberSet ?? new HashSet<ISymbol>();
memberSet.Add(member);
......@@ -364,7 +363,7 @@ public void VerifyAllSymbolEndActionsExecuted()
{
lock (_gate)
{
Debug.Assert(_lazyPendingSymbolEndActionsOpt == null || _lazyPendingSymbolEndActionsOpt.Count == 0);
Debug.Assert(_lazyPendingMemberSymbolsMapOpt == null || _lazyPendingMemberSymbolsMapOpt.Count == 0);
Debug.Assert(_lazyPendingSymbolEndActionsOpt == null || _lazyPendingSymbolEndActionsOpt.Count == 0);
}
}
......
......@@ -353,8 +353,7 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana
GetAnalyzerExecutionContext(analyzer).MarkSymbolEndAnalysisComplete(symbol);
}
// https://github.com/dotnet/roslyn/issues/30309 tracks enabling the below debug verification.
[Conditional("DEBUG_30309")]
[Conditional("DEBUG")]
public void VerifyAllSymbolEndActionsExecuted()
{
foreach (var analyzerExecutionContext in _analyzerExecutionContextMap.Values)
......
......@@ -96,5 +96,18 @@ internal static INamespaceSymbol GetNestedNamespace(this INamespaceSymbol contai
internal static bool IsNetModule(this IAssemblySymbol assembly) =>
assembly is ISourceAssemblySymbol sourceAssembly && sourceAssembly.Compilation.Options.OutputKind.IsNetModule();
internal static bool IsInSource(this ISymbol symbol)
{
foreach (var location in symbol.Locations)
{
if (location.IsInSource)
{
return true;
}
}
return false;
}
}
}
......@@ -1672,18 +1672,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Sub
Friend Function ShouldAddEvent(symbol As Symbol) As Boolean
If EventQueue Is Nothing Then
Return False
End If
For Each location As Location In symbol.Locations
If location.SourceTree IsNot Nothing Then
Debug.Assert(AllSyntaxTrees.Contains(location.SourceTree))
Return True
End If
Next
Return False
Return EventQueue IsNot Nothing AndAlso symbol.IsInSource()
End Function
Friend Sub SymbolDeclaredEvent(symbol As Symbol)
......
......@@ -1535,5 +1535,31 @@ Block[B2] - Exit
ControlFlowGraphVerifier.VerifyGraph(compilation, expectedFlowGraph, actualFlowGraph)
Next
End Sub
<Fact, WorkItem(30309, "https://github.com/dotnet/roslyn/issues/30309")>
Public Sub TestSymbolStartAnalyzer_MyApplication()
Dim sources = <compilation>
<file name="a.vb"><![CDATA[
Namespace My
Friend Partial Class MyApplication
End Class
End Namespace
]]></file>
</compilation>
Dim defines = AddPredefinedPreprocessorSymbols(OutputKind.WindowsApplication)
defines = defines.Add(KeyValuePairUtil.Create("_MyType", CObj("WindowsForms")))
Dim parseOptions = New VisualBasicParseOptions(preprocessorSymbols:=defines)
Dim compilationOptions = TestOptions.ReleaseExe.WithParseOptions(parseOptions)
Dim compilation = CreateCompilationWithMscorlib40AndVBRuntime(sources, {SystemWindowsFormsRef}, options:=compilationOptions)
compilation.VerifyDiagnostics()
Dim analyzers = New DiagnosticAnalyzer() {New SymbolStartAnalyzer(topLevelAction:=False, SymbolKind.NamedType)}
compilation.VerifyAnalyzerDiagnostics(analyzers, Nothing, Nothing, False,
Diagnostic("SymbolStartRuleId").WithArguments("MyApplication", "Analyzer1").WithLocation(1, 1))
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册