Skip to content

Commit 16e8613

Browse files
authored
Merge pull request #15087 from michaelnebel/csharp/stubgenrefreadonly
C#: Stub generator support for `ref readonly` parameters.
2 parents 56507c2 + b7f4bfe commit 16e8613

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

csharp/extractor/Semmle.Extraction.CSharp.StubGenerator/StubVisitor.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ private void StubParameters(ICollection<IParameterSymbol> parameters)
534534
case RefKind.In:
535535
stubWriter.Write("in ");
536536
break;
537+
case RefKind.RefReadOnlyParameter:
538+
stubWriter.Write("ref readonly ");
539+
break;
537540
default:
538541
stubWriter.Write($"/* TODO: {parameter.RefKind} */");
539542
break;
@@ -884,4 +887,4 @@ public override void VisitProperty(IPropertySymbol symbol)
884887
if (explicitInterfaceImplementations.Length == 0)
885888
StubProperty(symbol, null);
886889
}
887-
}
890+
}

csharp/extractor/Semmle.Extraction.Tests/StubGenerator.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void StubGeneratorMethodTest()
4242
// Setup
4343
const string source = @"
4444
public class MyTest {
45-
public int M1(string arg1) { return 0;}
45+
public int M1(string arg1) { return 0; }
4646
}";
4747

4848
// Execute
@@ -56,6 +56,26 @@ public class MyTest {
5656
Assert.Equal(expected, stub);
5757
}
5858

59+
[Fact]
60+
public void StubGeneratorRefReadonlyParameterTest()
61+
{
62+
// Setup
63+
const string source = @"
64+
public class MyTest {
65+
public int M1(ref readonly Guid guid) { return 0; }
66+
}";
67+
68+
// Execute
69+
var stub = GenerateStub(source);
70+
71+
// Verify
72+
const string expected = @"public class MyTest {
73+
public int M1(ref readonly Guid guid) => throw null;
74+
}
75+
";
76+
Assert.Equal(expected, stub);
77+
}
78+
5979
private static string GenerateStub(string source)
6080
{
6181
var st = CSharpSyntaxTree.ParseText(source);

0 commit comments

Comments
 (0)