The Wayback Machine - https://web.archive.org/web/20210218145646/https://github.com/dotnet/roslyn/commit/c97b744967352897f9ee3a9b1f21fc6c4fe5084c
Skip to content
Permalink
Browse files

Merge pull request #49987 from dotnet/features/ioperation

Merge features/ioperation into master
  • Loading branch information
msftbot committed Dec 16, 2020
2 parents 64769f8 + df0bce1 commit c97b744967352897f9ee3a9b1f21fc6c4fe5084c
Showing with 8,739 additions and 12,486 deletions.
  1. +1 −1 Compilers.slnf
  2. +12 −10 eng/generate-compiler-code.ps1
  3. +2 −2 ...es/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs
  4. +4 −4 src/Analyzers/Core/Analyzers/SimplifyInterpolation/Helpers.cs
  5. +2 −2 .../Analyzers/UseConditionalExpression/ForAssignment/UseConditionalExpressionForAssignmentHelpers.cs
  6. +3 −1 src/Analyzers/Core/Analyzers/UseConditionalExpression/UseConditionalExpressionHelpers.cs
  7. +4 −0 src/Analyzers/Core/Analyzers/UseSystemHashCode/Analyzer.OperationDeconstructor.cs
  8. +4 −4 src/Analyzers/Core/Analyzers/UseSystemHashCode/Analyzer.cs
  9. +2 −1 src/Analyzers/Core/CodeFixes/PopulateSwitch/AbstractPopulateSwitchExpressionCodeFixProvider.cs
  10. +1 −1 src/Analyzers/Core/CodeFixes/PopulateSwitch/AbstractPopulateSwitchStatementCodeFixProvider.cs
  11. +9 −1 src/Compilers/CSharp/Portable/Binder/ForEachEnumeratorInfo.cs
  12. +3 −1 src/Compilers/CSharp/Portable/Binder/ForEachLoopBinder.cs
  13. +0 −15 src/Compilers/CSharp/Portable/BoundTree/BoundConditionalOperator.cs
  14. +0 −15 src/Compilers/CSharp/Portable/BoundTree/BoundIfStatement.cs
  15. +0 −14 src/Compilers/CSharp/Portable/BoundTree/BoundSwitchSection.cs
  16. +12 −8 src/Compilers/CSharp/Portable/BoundTree/Constructors.cs
  17. +0 −13 src/Compilers/CSharp/Portable/BoundTree/IBoundConditional.cs
  18. +0 −14 src/Compilers/CSharp/Portable/BoundTree/IBoundSwitchSection.cs
  19. +3 −3 src/Compilers/CSharp/Portable/CSharpExtensions.cs
  20. +1 −1 src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
  21. +5 −6 src/Compilers/CSharp/Portable/Compilation/InitializerSemanticModel.cs
  22. +54 −36 src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.cs
  23. +12 −6 src/Compilers/CSharp/Portable/Compiler/MethodBodySynthesizer.cs
  24. +1 −1 src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
  25. +4 −2 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_AssignmentOperator.cs
  26. +10 −10 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_BinaryOperator.cs
  27. +7 −7 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs
  28. +2 −1 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Event.cs
  29. +10 −7 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForEachStatement.cs
  30. +9 −6 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_LockStatement.cs
  31. +2 −2 ...ompilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_NullCoalescingAssignmentOperator.cs
  32. +2 −2 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_NullCoalescingOperator.cs
  33. +2 −1 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_PropertyAccess.cs
  34. +8 −7 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
  35. +9 −9 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UnaryOperator.cs
  36. +1 −1 src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_UsingStatement.cs
  37. +643 −534 src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs
  38. +45 −68 src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory_Methods.cs
  39. +0 −1,987 src/Compilers/CSharp/Portable/Operations/CSharpOperationNodes.cs
  40. +57 −3 src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_ICoalesceAssignmentOperation.cs
  41. +661 −44 src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IForEachLoopStatement.cs
  42. +1 −1 src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IIsPatternExpression.cs
  43. +51 −0 src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_ITupleExpression.cs
  44. +253 −65 src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IUsingStatement.cs
  45. +38 −0 src/Compilers/CSharp/Test/Semantic/Semantics/OutVarTests.cs
  46. +14 −10 src/Compilers/Core/CodeAnalysisTest/Diagnostics/OperationTests.cs
  47. +13 −0 src/Compilers/Core/Portable/Collections/ArrayBuilderExtensions.cs
  48. +2 −0 src/Compilers/Core/Portable/Generated/FlowAnalysis.Generated.cs
  49. +4,170 −5,046 src/Compilers/Core/Portable/Generated/Operations.Generated.cs
  50. +0 −2 src/Compilers/Core/Portable/Operations/ArgumentKind.cs
  51. +7 −9 src/Compilers/Core/Portable/Operations/BasicBlock.cs
  52. +0 −2 src/Compilers/Core/Portable/Operations/BinaryOperatorKind.cs
  53. +0 −2 src/Compilers/Core/Portable/Operations/BranchKind.cs
  54. +0 −2 src/Compilers/Core/Portable/Operations/CaseKind.cs
  55. +4 −4 src/Compilers/Core/Portable/Operations/CommonConversion.cs
  56. +4 −5 src/Compilers/Core/Portable/Operations/ControlFlowBranch.cs
  57. +19 −18 src/Compilers/Core/Portable/Operations/ControlFlowGraph.cs
  58. +16 −14 src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.BasicBlockBuilder.cs
  59. +0 −3 src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.CaptureIdDispenser.cs
  60. +3 −5 src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.Context.cs
  61. +3 −5 src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.ImplicitInstanceInfo.cs
  62. +44 −26 src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.RegionBuilder.cs
  63. +601 −524 src/Compilers/Core/Portable/Operations/ControlFlowGraphBuilder.cs
  64. +6 −6 src/Compilers/Core/Portable/Operations/ControlFlowGraphExtensions.cs
  65. +4 −7 src/Compilers/Core/Portable/Operations/ControlFlowRegion.cs
  66. +0 −2 src/Compilers/Core/Portable/Operations/ControlFlowRegionKind.cs
  67. +0 −2 src/Compilers/Core/Portable/Operations/IConvertibleConversion.cs
  68. +6 −8 src/Compilers/Core/Portable/Operations/IOperation.cs
  69. +0 −2 src/Compilers/Core/Portable/Operations/InstanceReferenceKind.cs
  70. +7 −4 src/Compilers/Core/Portable/Operations/Loops/ForEachLoopOperationInfo.cs
  71. +5 −8 src/Compilers/Core/Portable/Operations/Loops/ForToLoopOperationInfo.cs
  72. +0 −2 src/Compilers/Core/Portable/Operations/Loops/LoopKind.cs
  73. +107 −0 src/Compilers/Core/Portable/Operations/Operation.Enumerable.cs
  74. +34 −167 src/Compilers/Core/Portable/Operations/Operation.cs
  75. +19 −624 src/Compilers/Core/Portable/Operations/OperationCloner.cs
  76. +12 −16 src/Compilers/Core/Portable/Operations/OperationExtensions.cs
  77. +7 −3 src/Compilers/Core/Portable/Operations/OperationFactory.cs
  78. +142 −126 src/Compilers/Core/Portable/Operations/OperationInterfaces.xml
  79. +73 −0 src/Compilers/Core/Portable/Operations/OperationMapBuilder.cs
  80. +306 −744 src/Compilers/Core/Portable/Operations/OperationNodes.cs
  81. +1 −3 src/Compilers/Core/Portable/Operations/OperationVisitor.cs
  82. +54 −15 src/Compilers/Core/Portable/Operations/OperationWalker.cs
  83. +0 −2 src/Compilers/Core/Portable/Operations/PlaceholderKind.cs
  84. +0 −2 src/Compilers/Core/Portable/Operations/UnaryOperatorKind.cs
  85. +4 −0 src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
  86. +0 −3 src/Compilers/Test/Core/CommonTestBase.cs
  87. +11 −11 src/Compilers/Test/Core/Compilation/OperationTreeVerifier.cs
  88. +20 −10 src/Compilers/Test/Core/Compilation/TestOperationVisitor.cs
  89. +33 −26 src/Compilers/VisualBasic/Portable/Binding/MemberSemanticModel.vb
  90. +0 −23 src/Compilers/VisualBasic/Portable/BoundTree/BoundDoLoop.vb
  91. +0 −27 src/Compilers/VisualBasic/Portable/BoundTree/BoundIfStatement.vb
  92. +0 −19 src/Compilers/VisualBasic/Portable/BoundTree/BoundTernaryConditionalExpression.vb
  93. +0 −26 src/Compilers/VisualBasic/Portable/BoundTree/BoundWhileStatement.vb
  94. +0 −11 src/Compilers/VisualBasic/Portable/BoundTree/IBoundConditional.vb
  95. +0 −11 src/Compilers/VisualBasic/Portable/BoundTree/IBoundConditionalLoop.vb
  96. +290 −311 src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory.vb
  97. +38 −52 src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationFactory_Methods.vb
  98. +0 −1,286 src/Compilers/VisualBasic/Portable/Operations/VisualBasicOperationNodes.vb
  99. +5 −5 src/Compilers/VisualBasic/Portable/VisualBasicExtensions.vb
  100. +182 −0 src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IUsingStatement.vb
  101. +2 −1 src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Rewriters/LocalDeclarationRewriter.cs
  102. +1 −1 src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/ExceptionLocalSymbol.cs
  103. +2 −1 src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/ObjectAddressLocalSymbol.cs
  104. +2 −1 src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/ObjectIdLocalSymbol.cs
  105. +2 −1 src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/PlaceholderLocalSymbol.cs
  106. +2 −1 src/ExpressionEvaluator/CSharp/Source/ExpressionCompiler/Symbols/ReturnValueLocalSymbol.cs
  107. +3 −2 ...res/CSharp/Portable/ConvertIfToSwitch/CSharpConvertIfToSwitchCodeRefactoringProvider.Rewriting.cs
  108. +2 −0 src/Features/CSharp/Portable/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
  109. +7 −5 src/Features/Core/Portable/InlineMethod/AbstractInlineMethodRefactoringProvider.InlineContext.cs
  110. +10 −5 ...atures/Core/Portable/InlineMethod/AbstractInlineMethodRefactoringProvider.MethodParametersInfo.cs
  111. +5 −0 src/Features/Core/Portable/InlineMethod/AbstractInlineMethodRefactoringProvider.cs
  112. +1 −1 ...ools/Source/CompilerGeneratorTools/Source/IOperationGenerator/CompilersIOperationGenerator.csproj
  113. +27 −0 src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/IOperationClassWriter.Verifier.cs
  114. +406 −272 src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/IOperationClassWriter.cs
  115. +16 −1 src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/Model.cs
  116. +27 −29 src/Tools/Source/CompilerGeneratorTools/Source/IOperationGenerator/Program.cs
  117. +1 −0 ...kspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Simplification/Simplifiers/CastSimplifier.cs
  118. +7 −7 src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/OperationExtensions.cs
@@ -71,4 +71,4 @@
"src\\Workspaces\\VisualBasic\\Portable\\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj"
]
}
}
}
@@ -8,10 +8,10 @@ param ([string]$configuration = "Debug",
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"

function Run-Tool($projectFilePath, $toolArgs) {
function Run-Tool($projectFilePath, $toolArgs, $targetFramework) {
$toolName = Split-Path -leaf $projectFilePath
Write-Host "Running $toolName $toolArgs"
Exec-Console $dotnet "run -p $projectFilePath --framework netcoreapp3.1 $toolArgs"
Exec-Console $dotnet "run -p $projectFilePath --framework $targetFramework $toolArgs"
}

function Run-LanguageCore($language, $languageSuffix, $languageDir, $syntaxProject, $errorFactsProject, $generatedDir, $generatedTestDir) {
@@ -22,18 +22,19 @@ function Run-LanguageCore($language, $languageSuffix, $languageDir, $syntaxProje
$errorFileName = if ($language -eq "CSharp") { "ErrorCode.cs" } else { "Errors.vb" }
$errorFilePath = Join-Path $languageDir "Errors\$errorFileName"
$errorGeneratedFilePath = Join-Path $generatedDir "ErrorFacts.Generated.$($languageSuffix)"
$targetFramework = "netcoreapp3.1"

Create-Directory $generatedDir
Create-Directory $generatedTestDir

# The C# syntax is now generated by a source generator
if ($language -ne "CSharp") {
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$generatedDir`""
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$generatedDir`"" $targetFramework
}
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$generatedDir`" /grammar"
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$syntaxTestFilePath`" /test"
Run-Tool $boundTreeGenProject "$language `"$boundFilePath`" `"$boundGeneratedFilePath`""
Run-Tool $errorFactsProject "`"$errorFilePath`" `"$errorGeneratedFilePath`""
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$generatedDir`" /grammar" $targetFramework
Run-Tool $syntaxProject "`"$syntaxFilePath`" `"$syntaxTestFilePath`" /test" $targetFramework
Run-Tool $boundTreeGenProject "$language `"$boundFilePath`" `"$boundGeneratedFilePath`"" $targetFramework
Run-Tool $errorFactsProject "`"$errorFilePath`" `"$errorGeneratedFilePath`"" $targetFramework
}

# Test the contents of our generated files to ensure they are equal. Compares our checked
@@ -73,13 +74,14 @@ function Run-IOperation($coreDir, $ioperationProject) {
$operationsDir = Join-Path $coreDir "Operations"
$operationsXml = Join-Path $operationsDir "OperationInterfaces.xml"
$generationDir = Join-Path $coreDir "Generated"
$targetFramework = "net5.0"

if (-not $test) {
Run-Tool $ioperationProject "`"$operationsXml`" `"$generationDir`""
Run-Tool $ioperationProject "`"$operationsXml`" `"$generationDir`"" $targetFramework
} else {
$scratchDir = Join-Path $generationTempDir "Core\Operations"
Create-Directory $scratchDir
Run-Tool $ioperationProject "`"$operationsXml`" `"$scratchDir`""
Run-Tool $ioperationProject "`"$operationsXml`" `"$scratchDir`"" $targetFramework
Test-GeneratedContent $generationDir $scratchDir
}
}
@@ -89,7 +91,7 @@ function Run-GetTextCore($generatedDir) {
$syntaxTextFilePath = Join-Path $generatedDir "Syntax.xml.GetText.Generated.vb"

Create-Directory $generatedDir
Run-Tool $basicSyntaxProject "`"$syntaxFilePath`" `"$syntaxTextFilePath`" /gettext"
Run-Tool $basicSyntaxProject "`"$syntaxFilePath`" `"$syntaxTextFilePath`" /gettext" "netcoreapp3.1"
}

function Run-GetText() {
@@ -135,7 +135,7 @@ bool HasConditionalDirectives()

static bool IsSingleThrowNotImplementedOperation(IOperation firstBlock)
{
var compilation = firstBlock.SemanticModel.Compilation;
var compilation = firstBlock.SemanticModel!.Compilation;
var notImplementedExceptionType = compilation.NotImplementedExceptionType();
if (notImplementedExceptionType == null)
return false;
@@ -182,7 +182,7 @@ static bool IsThrowNotImplementedOperation(INamedTypeSymbol notImplementedExcept
UnwrapImplicitConversion(throwOperation.Exception) is IObjectCreationOperation objectCreation &&
notImplementedExceptionType.Equals(objectCreation.Type);

static IOperation UnwrapImplicitConversion(IOperation value)
static IOperation? UnwrapImplicitConversion(IOperation? value)
=> value is IConversionOperation conversion && conversion.IsImplicit
? conversion.Operand
: value;
@@ -89,12 +89,12 @@ private static IOperation Unwrap(IOperation expression)
{
if (expression is IInvocationOperation { TargetMethod: { Name: nameof(ToString) } } invocation &&
HasNonImplicitInstance(invocation) &&
!syntaxFacts.IsBaseExpression(invocation.Instance.Syntax) &&
!invocation.Instance.Type.IsRefLikeType)
!syntaxFacts.IsBaseExpression(invocation.Instance!.Syntax) &&
!invocation.Instance.Type!.IsRefLikeType)
{
if (invocation.Arguments.Length == 1 &&
invocation.Arguments[0].Value is ILiteralOperation { ConstantValue: { HasValue: true, Value: string value } } literal &&
invocation.SemanticModel.Compilation.GetTypeByMetadataName(typeof(System.IFormattable).FullName!) is { } systemIFormattable &&
invocation.SemanticModel!.Compilation.GetTypeByMetadataName(typeof(System.IFormattable).FullName!) is { } systemIFormattable &&
invocation.Instance.Type.Implements(systemIFormattable))
{
unwrapped = invocation.Instance;
@@ -164,7 +164,7 @@ private static TextSpan GetSpanWithinLiteralQuotes(IVirtualCharService virtualCh
{
var alignmentSyntax = alignmentOp.Syntax;

unwrapped = invocation.Instance;
unwrapped = invocation.Instance!;
alignment = alignmentSyntax as TExpressionSyntax;
negate = targetName == nameof(string.PadRight);

@@ -14,7 +14,7 @@ internal static class UseConditionalExpressionForAssignmentHelpers
ISyntaxFacts syntaxFacts,
IConditionalOperation ifOperation,
[NotNullWhen(true)] out IOperation trueStatement,
[NotNullWhen(true)] out IOperation falseStatement,
[NotNullWhen(true)] out IOperation? falseStatement,
out ISimpleAssignmentOperation? trueAssignment,
out ISimpleAssignmentOperation? falseAssignment)
{
@@ -52,7 +52,7 @@ internal static class UseConditionalExpressionForAssignmentHelpers
}

private static bool TryGetAssignmentOrThrow(
IOperation statement,
[NotNullWhen(true)] IOperation? statement,
out ISimpleAssignmentOperation? assignment,
out IThrowOperation? throwOperation)
{
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Operations;

@@ -48,7 +49,8 @@ internal static partial class UseConditionalExpressionHelpers
/// Will unwrap a block with a single statement in it to just that block. Used so we can
/// support both <c>if (expr) { statement }</c> and <c>if (expr) statement</c>
/// </summary>
public static IOperation UnwrapSingleStatementBlock(IOperation statement)
[return: NotNullIfNotNull("statement")]
public static IOperation? UnwrapSingleStatementBlock(IOperation? statement)
=> statement is IBlockOperation block && block.Operations.Length == 1
? block.Operations[0]
: statement;
@@ -4,9 +4,11 @@

using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.UseSystemHashCode
{
@@ -79,6 +81,7 @@ public bool TryAddHashedSymbol(IOperation value, bool seenHash)
// (hashCode * -1521134295 + a.GetHashCode()).GetHashCode()
//
// recurse on the value we're calling GetHashCode on.
RoslynDebug.Assert(invocation.Instance is not null);
return TryAddHashedSymbol(invocation.Instance, seenHash: true);
}

@@ -106,6 +109,7 @@ public bool TryAddHashedSymbol(IOperation value, bool seenHash)
if (binary.OperatorKind == BinaryOperatorKind.Equals)
{
// (StringProperty == null ? 0 : StringProperty.GetHashCode())
RoslynDebug.Assert(conditional.WhenFalse is not null);
return TryAddHashedSymbol(conditional.WhenFalse, seenHash: true);
}
else if (binary.OperatorKind == BinaryOperatorKind.NotEquals)
@@ -99,13 +99,13 @@ public static bool TryGetAnalyzer(Compilation compilation, [NotNullWhen(true)] o
return null;
}

if (!(statements[0] is IReturnOperation returnOperation))
if (!(statements[0] is IReturnOperation { ReturnedValue: { } returnedValue }))
{
return null;
}

using var analyzer = new OperationDeconstructor(this, method, hashCodeVariable: null);
if (!analyzer.TryAddHashedSymbol(returnOperation.ReturnedValue, seenHash: false))
if (!analyzer.TryAddHashedSymbol(returnedValue, seenHash: false))
{
return null;
}
@@ -134,7 +134,7 @@ public static bool TryGetAnalyzer(Compilation compilation, [NotNullWhen(true)] o
// First statement has to be the declaration of the accumulator.
// Last statement has to be the return of it.
if (!(statements.First() is IVariableDeclarationGroupOperation varDeclStatement) ||
!(statements.Last() is IReturnOperation returnStatement))
!(statements.Last() is IReturnOperation { ReturnedValue: { } returnedValue }))
{
return null;
}
@@ -160,7 +160,7 @@ public static bool TryGetAnalyzer(Compilation compilation, [NotNullWhen(true)] o
}

var hashCodeVariable = declarator.Symbol;
if (!(IsLocalReference(returnStatement.ReturnedValue, hashCodeVariable)))
if (!(IsLocalReference(returnedValue, hashCodeVariable)))
{
return null;
}
@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.PopulateSwitch
{
@@ -40,7 +41,7 @@ protected AbstractPopulateSwitchExpressionCodeFixProvider()
}

protected sealed override ITypeSymbol GetSwitchType(ISwitchExpressionOperation switchExpression)
=> switchExpression.Value.Type;
=> switchExpression.Value.Type ?? throw ExceptionUtilities.Unreachable;

protected sealed override ICollection<ISymbol> GetMissingEnumMembers(ISwitchExpressionOperation switchOperation)
=> PopulateSwitchExpressionHelpers.GetMissingEnumMembers(switchOperation);
@@ -57,7 +57,7 @@ protected AbstractPopulateSwitchStatementCodeFixProvider()
}

protected sealed override ITypeSymbol GetSwitchType(ISwitchOperation switchOperation)
=> switchOperation.Value.Type;
=> switchOperation.Value.Type ?? throw ExceptionUtilities.Unreachable;

protected sealed override ICollection<ISymbol> GetMissingEnumMembers(ISwitchOperation switchOperation)
=> PopulateSwitchStatementHelpers.GetMissingEnumMembers(switchOperation);
@@ -27,7 +27,7 @@ internal sealed class ForEachEnumeratorInfo
public readonly MethodSymbol MoveNextMethod;

// True if the enumerator needs disposal once used.
// Will be either IDisposable/IAsyncDisposable, or use DisposeMethod below if set
// Will be either IDisposable/IAsyncDisposable, or use DisposeMethod below if set
// Computed during initial binding so that we can expose it in the semantic model.
public readonly bool NeedsDisposal;

@@ -39,6 +39,9 @@ internal sealed class ForEachEnumeratorInfo
// When using pattern-based Dispose, this stores the method to invoke to Dispose
public readonly MethodSymbol DisposeMethod;

// When enumerator needs disposing, this records if the dispose is pattern based or not
public readonly bool IsPatternDispose;

// Conversions that will be required when the foreach is lowered.
public readonly Conversion CollectionConversion; //collection expression to collection type
public readonly Conversion CurrentConversion; // current to element type
@@ -59,6 +62,7 @@ internal sealed class ForEachEnumeratorInfo
bool needsDisposal,
BoundAwaitableInfo disposeAwaitableInfo,
MethodSymbol disposeMethod,
bool isPatternDispose,
Conversion collectionConversion,
Conversion currentConversion,
Conversion enumeratorConversion,
@@ -71,6 +75,7 @@ internal sealed class ForEachEnumeratorInfo
Debug.Assert((object)currentPropertyGetter != null, "Field 'currentPropertyGetter' cannot be null");
Debug.Assert((object)moveNextMethod != null, "Field 'moveNextMethod' cannot be null");
Debug.Assert(binder != null, "Field 'binder' cannot be null");
Debug.Assert(!isPatternDispose || needsDisposal);

this.CollectionType = collectionType;
this.ElementTypeWithAnnotations = elementType;
@@ -81,6 +86,7 @@ internal sealed class ForEachEnumeratorInfo
this.NeedsDisposal = needsDisposal;
this.DisposeAwaitableInfo = disposeAwaitableInfo;
this.DisposeMethod = disposeMethod;
this.IsPatternDispose = isPatternDispose;
this.CollectionConversion = collectionConversion;
this.CurrentConversion = currentConversion;
this.EnumeratorConversion = enumeratorConversion;
@@ -103,6 +109,7 @@ internal struct Builder
public bool NeedsDisposal;
public BoundAwaitableInfo DisposeAwaitableInfo;
public MethodSymbol DisposeMethod;
public bool IsPatternDispose;

public Conversion CollectionConversion;
public Conversion CurrentConversion;
@@ -130,6 +137,7 @@ public ForEachEnumeratorInfo Build(BinderFlags location)
NeedsDisposal,
DisposeAwaitableInfo,
DisposeMethod,
IsPatternDispose,
CollectionConversion,
CurrentConversion,
EnumeratorConversion,
@@ -612,7 +612,8 @@ private BoundExpression UnwrapCollectionExpressionIfNullable(BoundExpression col
return BoundCall.Synthesized(
syntax: exprSyntax,
receiverOpt: collectionExpr,
method: nullableValueGetter);
method: nullableValueGetter,
binder: this);
}
else
{
@@ -936,6 +937,7 @@ private void GetDisposalInfoForEnumerator(ref ForEachEnumeratorInfo.Builder buil
if (disposeMethod is object)
{
builder.NeedsDisposal = true;
builder.IsPatternDispose = true;
builder.DisposeMethod = disposeMethod;
}
patternDisposeDiags.Free();

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c97b744

Please sign in to comment.