SharpLab
SharpLab copied to clipboard
Crashes on "generic bomb"
Code to repro:
using System;
Console.WriteLine(Hmh<int, string>(10));
static string Hmh<T, U>(int r)
{
if (r == 0)
return typeof(T).AssemblyQualifiedName;
return Hmh<(T, U), (U, T)>(r - 1);
}
Thanks for reporting! I'll take a look.
Good catch! Fortunately after #824 this would not be a concern anymore (impact will be to your container only). I'll prioritize that and then get back to double-check this after.
Nice
Also crashes on this code (activating JIT x86):
using System;
using Something = System.Collections.Generic.List<object>;
public class C {
public static void Main() {
Console.WriteLine(
DateTime.Now.ToContent().AddRandom().RemoveFirst().AddRandom().RemoveFirst().ToString()
);
}
}
public interface IDoSomething {
void DoSomething(Something input);
}
public readonly record struct Default(object Content) : IDoSomething {
public void DoSomething(Something input) => input.Add(Content);
}
public readonly record struct RemoveFirst<T>(T Wrapped) : IDoSomething where T : IDoSomething {
public void DoSomething(Something input) {
input.RemoveAt(0);
Wrapped.DoSomething(input);
}
}
public readonly record struct AddRandom<T>(T Wrapped) : IDoSomething where T : IDoSomething {
public void DoSomething(Something input) {
Wrapped.DoSomething(input);
input.Add(DateTime.Now);
}
}
public static class Extensions {
public static Default ToContent(this object o) => new(o);
public static RemoveFirst<T> RemoveFirst<T>(this T w) where T : IDoSomething => new(w);
public static AddRandom<T> AddRandom<T>(this T w) where T : IDoSomething => new(w);
}