Skip to content

Commit

Permalink
Prevent IDE0290 in ref struct
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBraconi committed Jun 6, 2024
1 parent e1e7d07 commit 029eda1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ bool TryFindPrimaryConstructorCandidate(
if (primaryConstructor != null)
return false;

// Check if any of the parameters is a ref-like type
if (constructor.Parameters.Any(p => p.Type.IsRefLikeType))
return false;

primaryConstructor = constructor;
primaryConstructorDeclaration = constructorDeclaration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4100,4 +4100,30 @@ class C()
LanguageVersion = LanguageVersion.CSharp12,
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/73614")]
public async Task TestNotWithRefStruct()
{
await new VerifyCS.Test
{
TestCode = """
using System;
ref struct Sample
{
private ReadOnlySpan<char> _str;
public Sample(ReadOnlySpan<char> str)
{
_str = str;
}
public void MoveNext()
{
var span = _str;
}
}
""",
LanguageVersion = LanguageVersion.CSharp12,
}.RunAsync();
}
}

0 comments on commit 029eda1

Please sign in to comment.