Announcement

Collapse
No announcement yet.

Generic vs Type method overload - incorrect pick

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Generic vs Type method overload - incorrect pick

    Gitlab source: https://github.com/bridgedotnet/Bridge/issues/4120

    We have come across an issue, where we have 2 following methods in C#:


    GetComponent<T>();
    GetComponent(Type type);

    when using a generic <T> method in C#, it sometimes uses the incorrect one, the one that has non-generic Type argument. The issue is, it seems to work in some cases, but not in others.

    Steps To Reproduce

    https://deck.net/27387142635a0bae3e6e8d88b0b77153

    It works in above code example, cannot reproduce it there.

    Expected Result

    When using:

    GetComponent<IMyInterface>();
    Expected result is that this method overload would be used in bridge, not this one:

    GetComponent(typeof(IMyInterface));
    Actual Result

    Following overload was used in bridge, which is incorrect:

    GetComponent(typeof(IMyInterface));
    WORKING VERSION:

    - in bellow image you can see underlined code, it uses the first bridge overload of:

    GetComponent(Mynt.Create.Core.ECS.Graphics.Components.IRenderable2D);
    Click image for larger version

Name:	working-call.PNG
Views:	1
Size:	233.2 KB
ID:	6333

    - this is the GetComponent: source code. Originally in C#, this was the generic <T> method overload
    Click image for larger version

Name:	working-source.PNG
Views:	1
Size:	436.0 KB
ID:	6334

    NON-WORKING VERSION:

    - this is a different project, but the code looks identical, except now a different overload is used, the incorrect one from C# GetComponent(Type type);

    GetComponent$1(Mynt.Create.Core.ECS.Graphics.Components.IRenderable2D);
    Click image for larger version

Name:	not-working-call.PNG
Views:	1
Size:	226.5 KB
ID:	6335

    - again, this is a source code, incorrect overload GetComponent$1: was picked. The correct overload is above, which is GetComponent:

    Click image for larger version

Name:	not-working-source.PNG
Views:	1
Size:	594.1 KB
ID:	6336

    Bridge version: 17.9.0
Working...
X