-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOperation for recursive pattern and switch expression #31967
Merged
gafter
merged 8 commits into
dotnet:features/recursive-patterns
from
gafter:rpatterns-27749
Dec 27, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1b3094b
IOperation for recursive pattern and switch expression
gafter f46c408
Work in progress
gafter 6224a5c
Further work in progress
gafter d8305e1
Implement IRecursivePatternOperation
gafter 7da7397
Small changes per review.
gafter 6957141
Merge branch 'features/recursive-patterns' of https://github.com/dotn…
gafter 8a9f66b
Merge branch 'rpatterns-27749' of https://github.com/gafter/roslyn in…
gafter 557a5f3
Remove accidentally added file.
gafter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
|
@@ -1469,8 +1470,8 @@ internal sealed class CSharpLazyConstantPatternOperation : LazyConstantPatternOp | |
private readonly CSharpOperationFactory _operationFactory; | ||
private readonly BoundNode _value; | ||
|
||
internal CSharpLazyConstantPatternOperation(CSharpOperationFactory operationFactory, BoundNode value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) : | ||
base(semanticModel, syntax, isImplicit) | ||
internal CSharpLazyConstantPatternOperation(ITypeSymbol inputType, CSharpOperationFactory operationFactory, BoundNode value, SemanticModel semanticModel, SyntaxNode syntax, bool isImplicit) : | ||
base(inputType, semanticModel, syntax, isImplicit) | ||
{ | ||
_operationFactory = operationFactory; | ||
_value = value; | ||
|
@@ -1482,6 +1483,41 @@ protected override IOperation CreateValue() | |
} | ||
} | ||
|
||
/// <summary> | ||
/// Represents a C# recursive pattern. | ||
/// </summary> | ||
internal sealed partial class CSharpLazyRecursivePatternOperation : LazyRecursivePatternOperation | ||
{ | ||
private readonly CSharpOperationFactory _operationFactory; | ||
private readonly ImmutableArray<BoundSubpattern> _deconstructionSubpatterns; | ||
private readonly ImmutableArray<BoundSubpattern> _propertySubpatterns; | ||
public CSharpLazyRecursivePatternOperation( | ||
CSharpOperationFactory operationFactory, | ||
ITypeSymbol inputType, | ||
ITypeSymbol matchedType, | ||
ISymbol deconstructSymbol, | ||
ImmutableArray<BoundSubpattern> deconstructionSubpatterns, | ||
ImmutableArray<BoundSubpattern> propertySubpatterns, | ||
ISymbol declaredSymbol, | ||
SemanticModel semanticModel, | ||
SyntaxNode syntax, | ||
bool isImplicit) | ||
: base(inputType, matchedType, deconstructSymbol, declaredSymbol, semanticModel, syntax, isImplicit) | ||
{ | ||
_operationFactory = operationFactory; | ||
_deconstructionSubpatterns = deconstructionSubpatterns; | ||
_propertySubpatterns = propertySubpatterns; | ||
} | ||
public override ImmutableArray<IPatternOperation> CreateDeconstructionSubpatterns() | ||
{ | ||
return _deconstructionSubpatterns.SelectAsArray(p => (IPatternOperation)_operationFactory.Create(p.Pattern)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
public override ImmutableArray<(ISymbol, IPatternOperation)> CreatePropertySubpatterns() | ||
{ | ||
return _propertySubpatterns.SelectAsArray(p => ((ISymbol)p.Symbol, (IPatternOperation)_operationFactory.Create(p.Pattern))); | ||
} | ||
} | ||
|
||
internal sealed class CSharpLazyPatternCaseClauseOperation : LazyPatternCaseClauseOperation | ||
{ | ||
private readonly CSharpOperationFactory _operationFactory; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
x is null
? If the constant isnull
, then we should probably setAcceptsNull
to true.If the intention is to capture
IsVar
, then maybe the pattern should have anIsVar
property instead.As Fred pointed out in a test, should
AcceptsNull
be true when matching types that can't benull
in the first place (likeint
)? #ClosedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the declaration pattern only.
The spec for a
var
pattern is that it accepts null. The fact that it will never get null in some circumstances doesn't affect that fact.In reply to: 244032712 [](ancestors = 244032712)