Skip to content

Commit 7b86c26

Browse files
author
dotnet-automerge-bot
authored
Merge pull request #36765 from dotnet/merges/master-to-release/dev16.3-preview1
Merge master to release/dev16.3-preview1
2 parents 60c0b2f + f52cb4c commit 7b86c26

File tree

6 files changed

+125
-1
lines changed

6 files changed

+125
-1
lines changed

src/EditorFeatures/CSharpTest/DisposeAnalysis/DisposeObjectsBeforeLosingScopeTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5024,6 +5024,37 @@ void M1()
50245024
}");
50255025
}
50265026

5027+
[Fact, WorkItem(32100, "https://github.com/dotnet/roslyn/issues/32100")]
5028+
public async Task UsingDeclaration()
5029+
{
5030+
await TestDiagnosticsAsync(@"
5031+
using System;
5032+
class C : IDisposable
5033+
{
5034+
public void Dispose() { }
5035+
void M1()
5036+
{
5037+
[|using var c = new C()|];
5038+
}
5039+
}", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
5040+
}
5041+
5042+
[Fact, WorkItem(32100, "https://github.com/dotnet/roslyn/issues/32100")]
5043+
public async Task UsingDeclarationWithInitializer()
5044+
{
5045+
await TestDiagnosticsAsync(@"
5046+
using System;
5047+
class C : IDisposable
5048+
{
5049+
public int P { get; set; }
5050+
public void Dispose() { }
5051+
void M1()
5052+
{
5053+
[|using var c = new C() { P = 1 }|];
5054+
}
5055+
}", parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
5056+
}
5057+
50275058
[Fact]
50285059
public async Task MissingDisposeInMethodWithAttributes()
50295060
{

src/EditorFeatures/CSharpTest/RemoveUnusedParametersAndValues/RemoveUnusedValueAssignmentTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6999,5 +6999,48 @@ int M()
69996999
int M2() => 0;
70007000
}", options: PreferUnusedLocal, parseOptions: new CSharpParseOptions(LanguageVersion.CSharp8));
70017001
}
7002+
7003+
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedValues)]
7004+
[WorkItem(33464, "https://github.com/dotnet/roslyn/issues/33464")]
7005+
public async Task UsingDeclaration()
7006+
{
7007+
await TestMissingInRegularAndScriptAsync(
7008+
@"using System;
7009+
7010+
class C : IDisposable
7011+
{
7012+
public void Dispose()
7013+
{
7014+
}
7015+
7016+
void M()
7017+
{
7018+
using var [|x|] = new C();
7019+
}
7020+
}", options: PreferDiscard,
7021+
parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
7022+
}
7023+
7024+
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedValues)]
7025+
[WorkItem(33464, "https://github.com/dotnet/roslyn/issues/33464")]
7026+
public async Task UsingDeclarationWithInitializer()
7027+
{
7028+
await TestMissingInRegularAndScriptAsync(
7029+
@"using System;
7030+
7031+
class C : IDisposable
7032+
{
7033+
public int P { get; set; }
7034+
public void Dispose()
7035+
{
7036+
}
7037+
7038+
void M()
7039+
{
7040+
using var [|x|] = new C() { P = 1 };
7041+
}
7042+
}", options: PreferDiscard,
7043+
parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
7044+
}
70027045
}
70037046
}

src/Features/Core/Portable/DisposeAnalysis/DisposeObjectsBeforeLosingScopeDiagnosticAnalyzer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ private void PerformFlowAnalysisOnOperationBlock(
103103
ComputeDiagnostics(disposeDataAtExit, notDisposedDiagnostics, mayBeNotDisposedDiagnostics,
104104
disposeAnalysisResult, pointsToAnalysisResult);
105105

106+
if (disposeAnalysisResult.ControlFlowGraph.OriginalOperation.HasAnyOperationDescendant(o => o.Kind == OperationKind.None))
107+
{
108+
// Workaround for https://github.com/dotnet/roslyn/issues/32100
109+
// Bail out in presence of OperationKind.None - not implemented IOperation.
110+
return;
111+
}
112+
106113
// Report diagnostics preferring *not* disposed diagnostics over may be not disposed diagnostics
107114
// and avoiding duplicates.
108115
foreach (var diagnostic in notDisposedDiagnostics.Concat(mayBeNotDisposedDiagnostics))

src/Features/Core/Portable/RemoveUnusedParametersAndValues/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ private bool ShouldAnalyze(IOperation operationBlock, ISymbol owningSymbol)
331331
// Skip blocks from attributes (which have OperationKind.None) and parameter initializers.
332332
// We don't have any unused values in such operation blocks.
333333
return false;
334+
335+
default:
336+
if (operationBlock.HasAnyOperationDescendant(o => o.Kind == OperationKind.None))
337+
{
338+
// Workaround for https://github.com/dotnet/roslyn/issues/32100
339+
// Bail out in presence of OperationKind.None - not implemented IOperation.
340+
return false;
341+
}
342+
343+
break;
334344
}
335345

336346
// We currently do not support points-to analysis, which is needed to accurately track locations of

src/VisualStudio/Core/SolutionExplorerShim/AnalyzersCommandHandler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Immutable;
66
using System.ComponentModel.Composition;
77
using System.ComponentModel.Design;
8+
using System.Diagnostics;
89
using System.IO;
910
using System.Linq;
1011
using EnvDTE;
@@ -62,6 +63,7 @@ internal class AnalyzersCommandHandler : IAnalyzersCommandHandler, IVsUpdateSolu
6263
private Workspace _workspace;
6364

6465
private bool _allowProjectSystemOperations = true;
66+
private bool _initialized;
6567

6668
[ImportingConstructor]
6769
public AnalyzersCommandHandler(
@@ -112,6 +114,8 @@ public void Initialize(IMenuCommandService menuCommandService)
112114

113115
var buildManager = (IVsSolutionBuildManager)_serviceProvider.GetService(typeof(SVsSolutionBuildManager));
114116
buildManager.AdviseUpdateSolutionEvents(this, out var cookie);
117+
118+
_initialized = true;
115119
}
116120
}
117121

@@ -189,11 +193,13 @@ public IContextMenuController DiagnosticContextMenuController
189193

190194
private bool ShouldShowDiagnosticContextMenu(IEnumerable<object> items)
191195
{
192-
return items.All(item => item is BaseDiagnosticItem);
196+
return _initialized && items.All(item => item is BaseDiagnosticItem);
193197
}
194198

195199
private void UpdateDiagnosticContextMenu()
196200
{
201+
Debug.Assert(_initialized);
202+
197203
UpdateSeverityMenuItemsChecked();
198204
UpdateSeverityMenuItemsEnabled();
199205
UpdateOpenHelpLinkMenuItemVisibility();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+
Imports Microsoft.CodeAnalysis
4+
Imports Microsoft.CodeAnalysis.Test.Utilities
5+
Imports Microsoft.VisualStudio.LanguageServices.Implementation.SolutionExplorer
6+
Imports Roslyn.Test.Utilities
7+
8+
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SolutionExplorer
9+
Public Class AnalyzerCommandHandlerTests
10+
<Fact, Trait(Traits.Feature, Traits.Features.Diagnostics)>
11+
<WorkItem(36304, "https://github.com/dotnet/roslyn/issues/36304")>
12+
Public Sub TestLazyInitialization()
13+
Dim descriptor = New DiagnosticDescriptor(
14+
id:="TST0001",
15+
title:="A test diagnostic",
16+
messageFormat:="A test message",
17+
category:="Test",
18+
defaultSeverity:=DiagnosticSeverity.Error,
19+
isEnabledByDefault:=True)
20+
Dim diagnosticItem = New LegacyDiagnosticItem(Nothing, descriptor, ReportDiagnostic.Error, Nothing)
21+
22+
Dim handler = New AnalyzersCommandHandler(Nothing, Nothing, Nothing)
23+
Dim shown = handler.DiagnosticContextMenuController.ShowContextMenu({diagnosticItem}, Nothing)
24+
Debug.Assert(Not shown)
25+
End Sub
26+
End Class
27+
End Namespace

0 commit comments

Comments
 (0)