Skip to content

Commit c0e3e61

Browse files
authored
Add runtime test for static gsharedvt methods (#101489)
1 parent 43ba3a8 commit c0e3e61

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using Xunit;
6+
7+
public static class Runtime_94467
8+
{
9+
public interface ITypeChecker
10+
{
11+
static abstract bool Test<T>(T value);
12+
}
13+
14+
public interface IHandler
15+
{
16+
bool Test<T>(T value);
17+
}
18+
19+
public struct TypeChecker : ITypeChecker
20+
{
21+
public static bool Test<T>(T value) => true;
22+
}
23+
24+
public class Handler<TChecker> : IHandler where TChecker : ITypeChecker
25+
{
26+
public bool Test<T>(T value) => TChecker.Test(value);
27+
}
28+
29+
public static IHandler GetHandler() => new Handler<TypeChecker>();
30+
31+
[Fact]
32+
public static int Test()
33+
{
34+
try {
35+
var handler = GetHandler();
36+
if (handler.Test<bool>(true) && handler.Test<bool?>(true))
37+
return 100;
38+
else
39+
return 101;
40+
} catch (Exception) {
41+
return -1;
42+
}
43+
}
44+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

0 commit comments

Comments
 (0)