Skip to content

Commit

Permalink
Merge pull request #58729 from dotnet/merges/main-to-main-vs-deps
Browse files Browse the repository at this point in the history
Merge main to main-vs-deps
  • Loading branch information
dotnet-bot authored Jan 10, 2022
2 parents d16a9bb + acfd9b0 commit a78db7b
Show file tree
Hide file tree
Showing 55 changed files with 4,085 additions and 660 deletions.
7 changes: 0 additions & 7 deletions Roslyn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Comp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Installer.Package", "src\Setup\Installer\Installer.Package.csproj", "{6A68FDF9-24B3-4CB6-A808-96BF50D1BCE5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Workspaces.Desktop.UnitTests", "src\Workspaces\DesktopTest\Microsoft.CodeAnalysis.Workspaces.Desktop.UnitTests.csproj", "{23405307-7EFF-4774-8B11-8F5885439761}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Insertion", "Insertion", "{AFA5F921-0650-45E8-B293-51A0BB89DEA0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevDivInsertionFiles", "src\Setup\DevDivInsertionFiles\DevDivInsertionFiles.csproj", "{6362616E-6A47-48F0-9EE0-27800B306ACB}"
Expand Down Expand Up @@ -1148,10 +1146,6 @@ Global
{6A68FDF9-24B3-4CB6-A808-96BF50D1BCE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A68FDF9-24B3-4CB6-A808-96BF50D1BCE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A68FDF9-24B3-4CB6-A808-96BF50D1BCE5}.Release|Any CPU.Build.0 = Release|Any CPU
{23405307-7EFF-4774-8B11-8F5885439761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23405307-7EFF-4774-8B11-8F5885439761}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23405307-7EFF-4774-8B11-8F5885439761}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23405307-7EFF-4774-8B11-8F5885439761}.Release|Any CPU.Build.0 = Release|Any CPU
{6362616E-6A47-48F0-9EE0-27800B306ACB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6362616E-6A47-48F0-9EE0-27800B306ACB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6362616E-6A47-48F0-9EE0-27800B306ACB}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -1479,7 +1473,6 @@ Global
{B9843F65-262E-4F40-A0BC-2CBEF7563A44} = {C52D8057-43AF-40E6-A01B-6CDBB7301985}
{03607817-6800-40B6-BEAA-D6F437CD62B7} = {BE25E872-1667-4649-9D19-96B83E75A44E}
{6A68FDF9-24B3-4CB6-A808-96BF50D1BCE5} = {BE25E872-1667-4649-9D19-96B83E75A44E}
{23405307-7EFF-4774-8B11-8F5885439761} = {55A62CFA-1155-46F1-ADF3-BEEE51B58AB5}
{AFA5F921-0650-45E8-B293-51A0BB89DEA0} = {8DBA5174-B0AA-4561-82B1-A46607697753}
{6362616E-6A47-48F0-9EE0-27800B306ACB} = {AFA5F921-0650-45E8-B293-51A0BB89DEA0}
{8977A560-45C2-4EC2-A849-97335B382C74} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC}
Expand Down
16 changes: 11 additions & 5 deletions azure-pipelines-integration-corehost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ trigger:
# Automatic building of all PRs is disabled in the pipeline's trigger page.
# See https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml#comment-triggers
pr:
- main
- main-vs-deps
- release/*
- features/*
- demos/*
branches:
include:
- main
- main-vs-deps
- release/*
- features/*
- demos/*
paths:
exclude:
- docs/*
- .github/*

jobs:
- job: VS_Integration_CoreHost_Debug
Expand Down
16 changes: 11 additions & 5 deletions azure-pipelines-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ trigger:

# Branches that trigger builds on PR
pr:
- main
- main-vs-deps
- release/*
- features/*
- demos/*
branches:
include:
- main
- main-vs-deps
- release/*
- features/*
- demos/*
paths:
exclude:
- docs/*
- .github/*

jobs:
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
Expand Down
16 changes: 11 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ trigger:

# Branches that trigger builds on PR
pr:
- main
- main-vs-deps
- release/*
- features/*
- demos/*
branches:
include:
- main
- main-vs-deps
- release/*
- features/*
- demos/*
paths:
exclude:
- docs/*
- .github/*

# Windows Build and Test Jobs
jobs:
Expand Down
8 changes: 0 additions & 8 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
Keep the setting conditional. The toolset sets the assembly version to 42.42.42.42 if not set explicitly.
-->
<AssemblyVersion Condition="'$(OfficialBuild)' == 'true' or '$(DotNetUseShippingVersions)' == 'true'">$(MajorVersion).$(MinorVersion).0.0</AssemblyVersion>
<!--
Arcade overrides our VersionPrefix when MajorVersion and MinorVersion are specified. Clear them so that
we can keep the PatchVersion until we are using an SDK that includes https://github.com/dotnet/arcade/pull/3601
-->
<MajorVersion>
</MajorVersion>
<MinorVersion>
</MinorVersion>
<MicrosoftNetCompilersToolsetVersion>4.1.0-2.21609.7</MicrosoftNetCompilersToolsetVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.Immutable;
using System.Composition;
Expand All @@ -21,8 +19,8 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.ConvertSwitchStatementToExpression
{
Expand Down Expand Up @@ -77,41 +75,43 @@ protected override async Task FixAllAsync(
spans.Add(switchLocation.SourceSpan);

var properties = diagnostic.Properties;
var nodeToGenerate = (SyntaxKind)int.Parse(properties[Constants.NodeToGenerateKey]);
var shouldRemoveNextStatement = bool.Parse(properties[Constants.ShouldRemoveNextStatementKey]);
var nodeToGenerate = (SyntaxKind)int.Parse(properties[Constants.NodeToGenerateKey]!);
var shouldRemoveNextStatement = bool.Parse(properties[Constants.ShouldRemoveNextStatementKey]!);

var declaratorToRemoveLocationOpt = diagnostic.AdditionalLocations.ElementAtOrDefault(1);
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var declaratorToRemoveLocation = diagnostic.AdditionalLocations.ElementAtOrDefault(1);
var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

SyntaxNode declaratorToRemoveNodeOpt = null;
ITypeSymbol declaratorToRemoveTypeOpt = null;
SyntaxNode? declaratorToRemoveNode = null;
ITypeSymbol? declaratorToRemoveType = null;

if (declaratorToRemoveLocationOpt != null)
if (declaratorToRemoveLocation != null)
{
declaratorToRemoveNodeOpt = declaratorToRemoveLocationOpt.FindNode(cancellationToken);
declaratorToRemoveTypeOpt = semanticModel.GetDeclaredSymbol(declaratorToRemoveNodeOpt, cancellationToken).GetSymbolType();
declaratorToRemoveNode = declaratorToRemoveLocation.FindNode(cancellationToken);
declaratorToRemoveType = semanticModel.GetDeclaredSymbol(declaratorToRemoveNode, cancellationToken).GetSymbolType();
}

var switchStatement = (SwitchStatementSyntax)switchLocation.FindNode(getInnermostNodeForTie: true, cancellationToken);

var switchExpression = Rewriter.Rewrite(
switchStatement, semanticModel, declaratorToRemoveTypeOpt, nodeToGenerate,
switchStatement, semanticModel, declaratorToRemoveType, nodeToGenerate,
shouldMoveNextStatementToSwitchExpression: shouldRemoveNextStatement,
generateDeclaration: declaratorToRemoveLocationOpt is object);
generateDeclaration: declaratorToRemoveLocation is not null,
cancellationToken);

editor.ReplaceNode(switchStatement, switchExpression.WithAdditionalAnnotations(Formatter.Annotation));

if (declaratorToRemoveLocationOpt is object)
if (declaratorToRemoveLocation is not null)
{
editor.RemoveNode(declaratorToRemoveLocationOpt.FindNode(cancellationToken));
editor.RemoveNode(declaratorToRemoveLocation.FindNode(cancellationToken));
}

if (shouldRemoveNextStatement)
{
// Already morphed into the top-level switch expression.
SyntaxNode nextStatement = switchStatement.GetNextStatement();
var nextStatement = switchStatement.GetNextStatement();
Contract.ThrowIfNull(nextStatement);
Debug.Assert(nextStatement.IsKind(SyntaxKind.ThrowStatement, SyntaxKind.ReturnStatement));
editor.RemoveNode(nextStatement.IsParentKind(SyntaxKind.GlobalStatement) ? nextStatement.Parent : nextStatement);
editor.RemoveNode(nextStatement.IsParentKind(SyntaxKind.GlobalStatement) ? nextStatement.GetRequiredParent() : nextStatement);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,157 @@ int M()
_ => 0,
};
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
[WorkItem(58636, "https://github.com/dotnet/roslyn/issues/58636")]
public async Task TestRuntimeTypeConversion_Assignment1()
{
await VerifyCS.VerifyCodeFixAsync(
@"class Program
{
void M(string s)
{
object result;
[|switch|] (s)
{
case ""a"":
result = 1234;
break;
case ""b"":
result = 3.14;
break;
default:
throw new System.Exception();
}
}
}",
@"class Program
{
void M(string s)
{
object result = s switch
{
""a"" => 1234,
""b"" => (object)3.14,
_ => throw new System.Exception(),
};
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
[WorkItem(58636, "https://github.com/dotnet/roslyn/issues/58636")]
public async Task TestRuntimeTypeConversion_Assignment2()
{
await VerifyCS.VerifyCodeFixAsync(
@"class Program
{
void M(string s)
{
object result;
[|switch|] (s)
{
case ""a"":
result = 1234;
break;
case ""b"":
result = 3.14;
break;
case ""c"":
result = true;
break;
default:
throw new System.Exception();
}
}
}",
@"class Program
{
void M(string s)
{
object result = s switch
{
""a"" => 1234,
""b"" => 3.14,
""c"" => true,
_ => throw new System.Exception(),
};
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
[WorkItem(58636, "https://github.com/dotnet/roslyn/issues/58636")]
public async Task TestRuntimeTypeConversion_Return1()
{
await VerifyCS.VerifyCodeFixAsync(
@"class Program
{
object M(string s)
{
[|switch|] (s)
{
case ""a"":
return 1234;
case ""b"":
return 3.14;
default:
throw new System.Exception();
}
}
}",
@"class Program
{
object M(string s)
{
return s switch
{
""a"" => 1234,
""b"" => (object)3.14,
_ => throw new System.Exception(),
};
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertSwitchStatementToExpression)]
[WorkItem(58636, "https://github.com/dotnet/roslyn/issues/58636")]
public async Task TestRuntimeTypeConversion_Return2()
{
await VerifyCS.VerifyCodeFixAsync(
@"class Program
{
object M(string s)
{
[|switch|] (s)
{
case ""a"":
return 1234;
case ""b"":
return 3.14;
case ""c"":
return true;
default:
throw new System.Exception();
}
}
}",
@"class Program
{
object M(string s)
{
return s switch
{
""a"" => 1234,
""b"" => 3.14,
""c"" => true,
_ => throw new System.Exception(),
};
}
}");
}
}
Expand Down
Loading

0 comments on commit a78db7b

Please sign in to comment.