Skip to content

Stack overflow when emulating code which uses generic parameters #126

@ElektroKill

Description

@ElektroKill

When using the new Echo emulator to emulate the following snippet a stack overflow exception is hit when resolving generic parameter types.

public interface ITestInterface<out T, in U> {
    public T TestMethod(U u);
}

public class TestClass : ITestInterface<int, long> {
    public static ITestInterface<int, long> Instance = new TestClass();
    
    public int TestMethod(long u) {
        return (int)u;
    }
}

public static class Usage {
    public static int Use() {
        return TestClass.Instance.TestMethod(long.MaxValue);
    }
}

Code used to initiate the emulation:

var method = module.GetAllTypes().FirstOrDefault(x => x.Name == "Usage")?.Methods.FirstOrDefault(x => x.Name == "Use");

var vm = new CilVirtualMachine(module, false);
var frame = new CallFrame(method, vm.ValueFactory);
vm.CallStack.Push(frame);

vm.Run();

Running this code results in one of the following errors occurring:
explorer_iukCU08NNj
explorer_JAWZEeBLou

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdotnet-asmresolverIssues related to the .NET back-end powered by AsmResolveremulationIssue related to the emulation modules of Echo.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions