未验证 提交 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 @@ ...@@ -4,7 +4,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.Diagnostics namespace Microsoft.CodeAnalysis.Diagnostics
...@@ -170,7 +169,7 @@ void processMembers(IEnumerable<ISymbol> members) ...@@ -170,7 +169,7 @@ void processMembers(IEnumerable<ISymbol> members)
{ {
foreach (var member in members) foreach (var member in members)
{ {
if (!member.IsImplicitlyDeclared) if (!member.IsImplicitlyDeclared && member.IsInSource())
{ {
memberSet = memberSet ?? new HashSet<ISymbol>(); memberSet = memberSet ?? new HashSet<ISymbol>();
memberSet.Add(member); memberSet.Add(member);
...@@ -364,7 +363,7 @@ public void VerifyAllSymbolEndActionsExecuted() ...@@ -364,7 +363,7 @@ public void VerifyAllSymbolEndActionsExecuted()
{ {
lock (_gate) lock (_gate)
{ {
Debug.Assert(_lazyPendingSymbolEndActionsOpt == null || _lazyPendingSymbolEndActionsOpt.Count == 0); Debug.Assert(_lazyPendingMemberSymbolsMapOpt == null || _lazyPendingMemberSymbolsMapOpt.Count == 0);
Debug.Assert(_lazyPendingSymbolEndActionsOpt == null || _lazyPendingSymbolEndActionsOpt.Count == 0); Debug.Assert(_lazyPendingSymbolEndActionsOpt == null || _lazyPendingSymbolEndActionsOpt.Count == 0);
} }
} }
......
...@@ -353,8 +353,7 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana ...@@ -353,8 +353,7 @@ public void MarkSymbolEndAnalysisComplete(ISymbol symbol, DiagnosticAnalyzer ana
GetAnalyzerExecutionContext(analyzer).MarkSymbolEndAnalysisComplete(symbol); GetAnalyzerExecutionContext(analyzer).MarkSymbolEndAnalysisComplete(symbol);
} }
// https://github.com/dotnet/roslyn/issues/30309 tracks enabling the below debug verification. [Conditional("DEBUG")]
[Conditional("DEBUG_30309")]
public void VerifyAllSymbolEndActionsExecuted() public void VerifyAllSymbolEndActionsExecuted()
{ {
foreach (var analyzerExecutionContext in _analyzerExecutionContextMap.Values) foreach (var analyzerExecutionContext in _analyzerExecutionContextMap.Values)
......
...@@ -96,5 +96,18 @@ internal static INamespaceSymbol GetNestedNamespace(this INamespaceSymbol contai ...@@ -96,5 +96,18 @@ internal static INamespaceSymbol GetNestedNamespace(this INamespaceSymbol contai
internal static bool IsNetModule(this IAssemblySymbol assembly) => internal static bool IsNetModule(this IAssemblySymbol assembly) =>
assembly is ISourceAssemblySymbol sourceAssembly && sourceAssembly.Compilation.Options.OutputKind.IsNetModule(); 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 ...@@ -1672,18 +1672,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Sub End Sub
Friend Function ShouldAddEvent(symbol As Symbol) As Boolean Friend Function ShouldAddEvent(symbol As Symbol) As Boolean
If EventQueue Is Nothing Then Return EventQueue IsNot Nothing AndAlso symbol.IsInSource()
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
End Function End Function
Friend Sub SymbolDeclaredEvent(symbol As Symbol) Friend Sub SymbolDeclaredEvent(symbol As Symbol)
......
...@@ -1535,5 +1535,31 @@ Block[B2] - Exit ...@@ -1535,5 +1535,31 @@ Block[B2] - Exit
ControlFlowGraphVerifier.VerifyGraph(compilation, expectedFlowGraph, actualFlowGraph) ControlFlowGraphVerifier.VerifyGraph(compilation, expectedFlowGraph, actualFlowGraph)
Next Next
End Sub 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 Class
End Namespace End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册