SharpLab icon indicating copy to clipboard operation
SharpLab copied to clipboard

Crashes on "generic bomb"

Open WhiteBlackGoose opened this issue 3 years ago • 4 comments

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);
}

WhiteBlackGoose avatar Oct 13 '21 06:10 WhiteBlackGoose

Thanks for reporting! I'll take a look.

ashmind avatar Oct 21 '21 03:10 ashmind

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.

ashmind avatar Oct 22 '21 07:10 ashmind

Nice

WhiteBlackGoose avatar Oct 22 '21 09:10 WhiteBlackGoose

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);
}

Sebazzz avatar Mar 31 '24 20:03 Sebazzz