Skip to content

Commit e5058f6

Browse files
authored
Regression test for GitHub issue #74792 (Roslyn issue 63617) (#74804)
While investigating the bug 74792 I have created this regression test based on the Roslyn issue 63617. So far I haven't managed to repro the failure locally so I'm sending it to the lab. Please let me know if I created the test incorrectly so that it needs adjustments to hit the issue. Thanks Tomas
1 parent 5119157 commit e5058f6

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
6+
// This regression test tracks an externally reported issue where this
7+
// code fails at runtime with a BadImageFormatException because the
8+
// constraint resolver fails to confirm that L1 and L2 implement
9+
// ILogic when constructing instances of the struct G, cf:
10+
//
11+
// https://github.com/dotnet/roslyn/issues/63617
12+
// https://github.com/dotnet/runtime/issues/74792
13+
//
14+
// Apparently it was failing in an older version of the CoreCLR
15+
// runtime, as of now (around .NET 7 RC1 timeframe) the test passes.
16+
17+
class Program
18+
{
19+
public static int Main()
20+
{
21+
new G<L1>().Test();
22+
new G<L2>().Test();
23+
return 100;
24+
}
25+
}
26+
27+
public interface ILogic{
28+
abstract static void Run();
29+
}
30+
31+
public class L1 : ILogic{
32+
public static void Run(){
33+
Console.WriteLine("L1");
34+
}
35+
}
36+
37+
public class L2 : ILogic{
38+
public static void Run(){
39+
Console.WriteLine("L2");
40+
}
41+
}
42+
43+
struct G<T> where T : ILogic
44+
{
45+
public void Test()
46+
{
47+
T.Run();
48+
}
49+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
4+
<OutputType>Exe</OutputType>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="$(MSBuildProjectName).cs" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)