Skip to content

Dynamic Dispatch: Dynamic Dispatch with Generic Interfaces #9885

@wlewNV

Description

@wlewNV

Description

Generic interfaces like IFoo<T> should support dynamic dispatch when used as interface variants.

Test Cases

interface ICalculator<T>
{
    T compute(T a, T b);
}

struct Adder : ICalculator<float>
{
    float compute(float a, float b) { return a + b; }
}

struct Multiplier : ICalculator<float>
{
    float compute(float a, float b) { return a * b; }
}

ICalculator<float> makeCalc(int id)
{
    if (id == 0) return Adder();
    else return Multiplier();
}

void test()
{
    ICalculator<float> calc = makeCalc(0);
    float result = calc.compute(3.0, 4.0);  // Should dispatch correctly
}

Expected Behavior

Compiles and dispatches correctly at runtime for generic interface types.

Notes

  • Also test variadic generics: IFoo<each Ts> if supported
  • Test with different type arguments (int, float, structs)

Metadata

Metadata

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions