Skip to content

Commit

Permalink
Merge pull request #18495 from michaelnebel/csharp/refstrucinterfacet…
Browse files Browse the repository at this point in the history
…ests

C# 13: [TEST ONLY] ref structs are allowed to implement interfaces.
  • Loading branch information
michaelnebel authored Jan 16, 2025
2 parents 0452b4a + 8b6e552 commit 9021214
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
39 changes: 39 additions & 0 deletions csharp/ql/test/library-tests/implements/Implements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

public interface I1
{
object Prop { get; set; }
void M1();
}

public interface I2
{
object M2();
}

public class C : I1
{
public object Prop { get; set; }
public void M1() { }
}

public struct S : I1
{
public object Prop { get; set; }
public void M1() { }
public object M2() { throw null; }
}

public ref struct RS1 : I1
{
public object Prop { get; set; }
public void M1() { }
public object M2() { throw null; }
}

public ref struct RS2 : I1, I2
{
public object Prop { get; set; }
public void M1() { }
public object M2() { throw null; }
}
17 changes: 17 additions & 0 deletions csharp/ql/test/library-tests/implements/Implements.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
| Implements.cs:16:19:16:22 | Prop | Implements.cs:14:14:14:14 | C | Implements.cs:5:12:5:15 | Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:16:26:16:28 | get_Prop | Implements.cs:14:14:14:14 | C | Implements.cs:5:19:5:21 | get_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:16:31:16:33 | set_Prop | Implements.cs:14:14:14:14 | C | Implements.cs:5:24:5:26 | set_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:17:17:17:18 | M1 | Implements.cs:14:14:14:14 | C | Implements.cs:6:10:6:11 | M1 | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:22:19:22:22 | Prop | Implements.cs:20:15:20:15 | S | Implements.cs:5:12:5:15 | Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:22:26:22:28 | get_Prop | Implements.cs:20:15:20:15 | S | Implements.cs:5:19:5:21 | get_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:22:31:22:33 | set_Prop | Implements.cs:20:15:20:15 | S | Implements.cs:5:24:5:26 | set_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:23:17:23:18 | M1 | Implements.cs:20:15:20:15 | S | Implements.cs:6:10:6:11 | M1 | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:29:19:29:22 | Prop | Implements.cs:27:19:27:21 | RS1 | Implements.cs:5:12:5:15 | Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:29:26:29:28 | get_Prop | Implements.cs:27:19:27:21 | RS1 | Implements.cs:5:19:5:21 | get_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:29:31:29:33 | set_Prop | Implements.cs:27:19:27:21 | RS1 | Implements.cs:5:24:5:26 | set_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:30:17:30:18 | M1 | Implements.cs:27:19:27:21 | RS1 | Implements.cs:6:10:6:11 | M1 | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:36:19:36:22 | Prop | Implements.cs:34:19:34:21 | RS2 | Implements.cs:5:12:5:15 | Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:36:26:36:28 | get_Prop | Implements.cs:34:19:34:21 | RS2 | Implements.cs:5:19:5:21 | get_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:36:31:36:33 | set_Prop | Implements.cs:34:19:34:21 | RS2 | Implements.cs:5:24:5:26 | set_Prop | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:37:17:37:18 | M1 | Implements.cs:34:19:34:21 | RS2 | Implements.cs:6:10:6:11 | M1 | Implements.cs:3:18:3:19 | I1 |
| Implements.cs:38:19:38:20 | M2 | Implements.cs:34:19:34:21 | RS2 | Implements.cs:11:12:11:13 | M2 | Implements.cs:9:18:9:19 | I2 |
8 changes: 8 additions & 0 deletions csharp/ql/test/library-tests/implements/Implements.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import csharp

from Overridable o1, Overridable o2
where
o1.overridesOrImplements(o2) and
o1.fromSource() and
o2.fromSource()
select o1, o1.getDeclaringType(), o2, o2.getDeclaringType()

0 comments on commit 9021214

Please sign in to comment.