Skip to content
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

Finalize testing and implementation around object initializers for inline arrays. #68064

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5035,7 +5035,7 @@ private BoundExpression BindObjectInitializerMember(

MessageID.IDS_FeatureDictionaryInitializer.CheckFeatureAvailability(diagnostics, implicitIndexing.ArgumentList.OpenBracketToken);

boundMember = BindElementAccess(implicitIndexing, implicitReceiver, implicitIndexing.ArgumentList, diagnostics);
boundMember = BindElementAccess(implicitIndexing, implicitReceiver, implicitIndexing.ArgumentList, allowInlineArrayElementAccess: false, diagnostics);

resultKind = boundMember.ResultKind;
hasErrors = boundMember.HasAnyErrors || implicitReceiver.HasAnyErrors;
Expand Down Expand Up @@ -5144,8 +5144,6 @@ private BoundExpression BindObjectInitializerMember(
case BoundKind.PointerElementAccess:
return CheckValue(boundMember, valueKind, diagnostics);

// PROTOTYPE(InlineArrays): case BoundKind.InlineArrayAccess:

default:
return BadObjectInitializerMemberAccess(boundMember, implicitReceiver, leftSyntax, diagnostics, valueKind, hasErrors);
}
Expand Down Expand Up @@ -7937,10 +7935,10 @@ private static bool IsMethodOrPropertyGroup(ArrayBuilder<Symbol> members)
private BoundExpression BindElementAccess(ElementAccessExpressionSyntax node, BindingDiagnosticBag diagnostics)
{
BoundExpression receiver = BindExpression(node.Expression, diagnostics: diagnostics, invoked: false, indexed: true);
return BindElementAccess(node, receiver, node.ArgumentList, diagnostics);
return BindElementAccess(node, receiver, node.ArgumentList, allowInlineArrayElementAccess: true, diagnostics);
}

private BoundExpression BindElementAccess(ExpressionSyntax node, BoundExpression receiver, BracketedArgumentListSyntax argumentList, BindingDiagnosticBag diagnostics)
private BoundExpression BindElementAccess(ExpressionSyntax node, BoundExpression receiver, BracketedArgumentListSyntax argumentList, bool allowInlineArrayElementAccess, BindingDiagnosticBag diagnostics)
{
AnalyzedArguments analyzedArguments = AnalyzedArguments.GetInstance();
try
Expand All @@ -7957,15 +7955,15 @@ private BoundExpression BindElementAccess(ExpressionSyntax node, BoundExpression
receiver = CheckValue(receiver, BindValueKind.RValue, diagnostics);
receiver = BindToNaturalType(receiver, diagnostics);

return BindElementOrIndexerAccess(node, receiver, analyzedArguments, diagnostics);
return BindElementOrIndexerAccess(node, receiver, analyzedArguments, allowInlineArrayElementAccess, diagnostics);
}
finally
{
analyzedArguments.Free();
}
}

private BoundExpression BindElementOrIndexerAccess(ExpressionSyntax node, BoundExpression expr, AnalyzedArguments analyzedArguments, BindingDiagnosticBag diagnostics)
private BoundExpression BindElementOrIndexerAccess(ExpressionSyntax node, BoundExpression expr, AnalyzedArguments analyzedArguments, bool allowInlineArrayElementAccess, BindingDiagnosticBag diagnostics)
{
if ((object)expr.Type == null)
{
Expand All @@ -7985,7 +7983,8 @@ private BoundExpression BindElementOrIndexerAccess(ExpressionSyntax node, BoundE
}

if (expr.Type.HasInlineArrayAttribute(out _) && analyzedArguments.Arguments.Count == 1 && expr.Type.TryGetInlineArrayElementType() is { HasType: true } elementType &&
tryImplicitConversionToInlineArrayIndex(node, analyzedArguments.Arguments[0], diagnostics, out WellKnownType indexOrRangeWellknownType) is { } convertedIndex)
tryImplicitConversionToInlineArrayIndex(node, analyzedArguments.Arguments[0], diagnostics, out WellKnownType indexOrRangeWellknownType) is { } convertedIndex &&
allowInlineArrayElementAccess) // PROTOTYPE(InlineArrays): Check this first after conflicting PRs are merged
{
return bindInlineArrayElementAccess(node, expr, analyzedArguments, convertedIndex, indexOrRangeWellknownType, elementType, diagnostics);
}
Expand Down Expand Up @@ -9643,7 +9642,7 @@ private BoundExpression BindElementBindingExpression(ElementBindingExpressionSyn
{
BoundExpression receiver = GetReceiverForConditionalBinding(node, diagnostics);

var memberAccess = BindElementAccess(node, receiver, node.ArgumentList, diagnostics);
var memberAccess = BindElementAccess(node, receiver, node.ArgumentList, allowInlineArrayElementAccess: true, diagnostics);
return memberAccess;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ private void AddObjectInitializer(
break;
}

// PROTOTYPE(InlineArrays): case BoundKind.InlineArrayAccess:

case BoundKind.PointerElementAccess:
{
// Remember we haven't lowered this node yet.
Expand Down
Loading