-
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
List-patterns: factor binding logic #57318
Changes from 1 commit
025f398
00e6ff2
b1112ce
8d16d55
05f3611
1c3417a
51be8eb
c3f1618
ddb617c
d69d920
39ea1f6
91a7ffa
7f36c4f
0f924db
d1288ed
adfee13
dbdbe39
a1a4243
c9f67d1
05edc54
1912f37
cd501b4
aab5d74
8be23fa
6c132fa
a4ba54b
dff82c5
9def40b
2965f6d
dea39c5
174d3f2
bcc3336
76d6d7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -597,7 +597,11 @@ internal bool CheckValueKind(SyntaxNode node, BoundExpression expr, BindValueKin | |
return CheckValueKind(node, implicitIndexerAccess.IndexerAccess, valueKind, checkingReceiver, diagnostics); | ||
|
||
case BoundKind.IndexOrRangeIndexerPatternReceiverPlaceholder: | ||
return true; | ||
var receiverPlaceholder = (BoundIndexOrRangeIndexerPatternReceiverPlaceholder)expr; | ||
return CheckValueKind(node, receiverPlaceholder.Expression, valueKind, checkingReceiver, diagnostics); | ||
|
||
case BoundKind.DeconstructValuePlaceholder: | ||
break; | ||
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. 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. It's covered by |
||
|
||
case BoundKind.ConditionalOperator: | ||
var conditional = (BoundConditionalOperator)expr; | ||
|
@@ -622,13 +626,46 @@ internal bool CheckValueKind(SyntaxNode node, BoundExpression expr, BindValueKin | |
case BoundKind.AssignmentOperator: | ||
var assignment = (BoundAssignmentOperator)expr; | ||
return CheckSimpleAssignmentValueKind(node, assignment, valueKind, diagnostics); | ||
|
||
default: | ||
Debug.Assert(expr is not BoundValuePlaceholderBase, $"Placeholder kind {expr.Kind} should be explicitly handled"); | ||
break; | ||
} | ||
|
||
// At this point we should have covered all the possible cases for anything that is not a strict RValue. | ||
Error(diagnostics, GetStandardLvalueError(valueKind), node); | ||
return false; | ||
} | ||
|
||
private static BoundExpression UnwrapPlaceholdersIfNeeded(BoundExpression? e) | ||
{ | ||
switch (e) | ||
{ | ||
case null: | ||
return null; | ||
|
||
case BoundIndexOrRangeIndexerPatternReceiverPlaceholder placeholder: | ||
return placeholder.Expression; | ||
|
||
case BoundSlicePatternReceiverPlaceholder: | ||
case BoundListPatternReceiverPlaceholder: | ||
case BoundObjectOrCollectionValuePlaceholder: | ||
case BoundAwaitableValuePlaceholder: | ||
case BoundInterpolatedStringHandlerPlaceholder: | ||
case BoundDisposableValuePlaceholder: | ||
// TODO2 | ||
return e; | ||
|
||
case BoundDeconstructValuePlaceholder: | ||
// PROTOTYPE file issue | ||
return e; | ||
|
||
default: | ||
Debug.Assert(e is not BoundValuePlaceholderBase, $"Placeholder kind {e.Kind} should be explicitly handled"); | ||
return e; | ||
} | ||
} | ||
|
||
private static bool CheckNotNamespaceOrType(BoundExpression expr, BindingDiagnosticBag diagnostics) | ||
{ | ||
switch (expr.Kind) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8056,7 +8056,7 @@ private bool TryBindIndexOrRangeImplicitIndexer( | |
_ => GetValEscape(receiverOpt, LocalScopeDepth) | ||
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. 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. Indeed. Thanks |
||
}; | ||
|
||
var receiverPlaceholder = new BoundIndexOrRangeIndexerPatternReceiverPlaceholder(receiverOpt.Syntax, receiverValEscape, receiverOpt.Type) { WasCompilerGenerated = true }; | ||
var receiverPlaceholder = new BoundIndexOrRangeIndexerPatternReceiverPlaceholder(receiverOpt.Syntax, receiverValEscape, receiverOpt, receiverOpt.Type) { WasCompilerGenerated = true }; | ||
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. |
||
if (!TryBindIndexOrRangeImplicitIndexer(syntax, receiverPlaceholder, receiverType, argIsIndex: argIsIndex, | ||
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. |
||
out var lengthOrCountAccess, out var indexerOrSliceAccess, out var argumentPlaceholders, diagnostics)) | ||
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: consider indenting #Closed |
||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1464,7 +1464,7 @@ internal bool CheckImplicitThisCopyInReadOnlyMember(BoundExpression receiver, Me | |
{ | ||
// For now we are warning only in implicit copy scenarios that are only possible with readonly members. | ||
// Eventually we will warn on implicit value copies in more scenarios. See https://github.com/dotnet/roslyn/issues/33968. | ||
if (receiver is BoundThisReference && | ||
if (UnwrapPlaceholdersIfNeeded(receiver) is BoundThisReference && | ||
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. |
||
receiver.Type.IsValueType && | ||
ContainingMemberOrLambda is MethodSymbol containingMethod && | ||
containingMethod.IsEffectivelyReadOnly && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,8 @@ | |
<Node Name="BoundIndexOrRangeIndexerPatternReceiverPlaceholder" Base="BoundValuePlaceholderBase"> | ||
<Field Name="Type" Type="TypeSymbol" Override="true" Null="disallow"/> | ||
<Field Name="ValEscape" Type="uint" Null="NotApplicable"/> | ||
<!-- For CheckValue --> | ||
<Field Name="Expression" Type="BoundExpression"/> | ||
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. |
||
</Node> | ||
|
||
<!-- This node represents the receiver for a list pattern. It does not survive lowering --> | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -975,16 +975,20 @@ internal static bool CanBePassedByReference(BoundExpression expr) | |
case BoundKind.IndexOrRangePatternIndexerAccess: | ||
return CanBePassedByReference(((BoundIndexOrRangePatternIndexerAccess)expr).IndexerAccess); | ||
|
||
// TODO2 I'm not sure about this | ||
case BoundKind.IndexOrRangeIndexerPatternReceiverPlaceholder: | ||
case BoundKind.IndexOrRangeIndexerPatternValuePlaceholder: | ||
case BoundKind.ListPatternReceiverPlaceholder: | ||
case BoundKind.ListPatternUnloweredIndexPlaceholder: | ||
case BoundKind.SlicePatternReceiverPlaceholder: | ||
case BoundKind.SlicePatternUnloweredRangePlaceholder: | ||
return true; | ||
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. |
||
|
||
case BoundKind.Conversion: | ||
return expr is BoundConversion { Conversion: { IsInterpolatedStringHandler: true }, Type: { IsValueType: true } }; | ||
} | ||
|
||
Debug.Assert(expr is not BoundValuePlaceholderBase, $"Placeholder kind {expr.Kind} must be handled explicitly"); | ||
|
||
return false; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,7 @@ private BoundSequence VisitIndexOrRangePatternIndexerAccess(BoundIndexOrRangePat | |
private BoundSequence VisitIndexImplicitIndexerAccess(BoundIndexOrRangePatternIndexerAccess node, bool isLeftOfAssignment) // TODO2 we're not using isLeftOfAssignment | ||
{ | ||
Debug.Assert(node.ArgumentPlaceholders.Length == 1); | ||
Debug.Assert(node.IndexerAccess is BoundIndexerAccess); | ||
|
||
Debug.Assert(TypeSymbol.Equals( | ||
node.Argument.Type, | ||
|
@@ -322,6 +323,7 @@ private BoundExpression MakePatternIndexOffsetExpression( | |
private BoundSequence VisitRangeImplicitIndexerAccess(BoundIndexOrRangePatternIndexerAccess node) | ||
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. |
||
{ | ||
Debug.Assert(node.ArgumentPlaceholders.Length == 2); | ||
Debug.Assert(node.IndexerAccess is BoundCall); | ||
|
||
Debug.Assert(TypeSymbol.Equals( | ||
node.Argument.Type, | ||
|
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.
return CheckValueKind(node, receiverPlaceholder.Expression, valueKind, checkingReceiver, diagnostics);
Note to self, please, ignore. #Closed