Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Microsoft.CodeAnalysis.Operations;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.MakeStructMemberReadOnly;

Expand Down Expand Up @@ -331,6 +330,10 @@ private static bool OperationPotentiallyMutatesThis(

if (operation is IInlineArrayAccessOperation)
{
// to determine if this is safe to make into a ReadOnlySpan or not.
if (operation.Type.IsSpan())
return true;

// If we're writing into an inline-array off of 'this'. Then we can't make this `readonly`.
if (CSharpSemanticFacts.Instance.IsWrittenTo(semanticModel, operation.Syntax, cancellationToken))
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2345,4 +2345,33 @@ public int Z
LanguageVersion = LanguageVersion.CSharp12,
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
}.RunAsync();

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/79384")]
public Task TestSpanFromInlineArray()
=> new VerifyCS.Test
{
TestCode = """
using System.Runtime.CompilerServices;

public struct Example
{
private Buffer _buffer;

public void Set(int index, int value)
{
var bufferSpan = _buffer[..0];

bufferSpan[0] = value;
}
}

[InlineArray(1)]
public struct Buffer
{
private int _element0;
}
""",
LanguageVersion = LanguageVersion.CSharp13,
ReferenceAssemblies = ReferenceAssemblies.Net.Net90,
}.RunAsync();
}
Loading