Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

SuperNodes Generated with Explicit Interface Definitions #18

Open
CoreyAlexander opened this issue Jan 15, 2024 · 2 comments
Open

SuperNodes Generated with Explicit Interface Definitions #18

CoreyAlexander opened this issue Jan 15, 2024 · 2 comments

Comments

@CoreyAlexander
Copy link

When using explicit interface definitions like below, the SuperNode generated fails to generate correctly for the following case.

For example:

The given interface.

public interface IHaveAutoload<T> {
    T Instance { get; }
}

The given class.

[GlobalClass, SuperNode(typeof(Dependent))]
public partial class Component: Node2D, IHaveAutoload<SignalAutoload>, IHaveAutoload<AnotherAutoload> {
    protected AnotherAutoload anotherAutoload = null!;
    AnotherAutoload IHaveAutoload<AnotherAutoload>.Instance => this.anotherAutoload;

    protected SignalAutoload signalAutoload = null!;
    SignalAutoload IHaveAutoload<SignalAutoload>.Instance => this.signalAutoload;

    public override void _Ready() {
        this.anotherAutoload = this.GetNode<AnotherAutoload>(
            "/root/AnotherAutoload"
        );

        this.signalAutoload = this.GetNode<SignalAutoload>(
            "/root/SignalAutoload"
        );
    }
}

Produces inside of the generated SuperNode:

    public static TResult ReceiveScriptPropertyOrFieldType<TResult>(
      string scriptProperty, ITypeReceiver<TResult> receiver
    ) {
      switch (scriptProperty) {
        case "Instance":
          return receiver.Receive<NameSpaceOfAutoloadClass>();
        case "Instance":
          return receiver.Receive<NameSpaceOfAutoloadClass>();
    }
}

    public dynamic? GetScriptPropertyOrField(string scriptProperty) {
      switch (scriptProperty) {
        case "Instance":
          return (()this).Instance;
        case "Instance":
          return (()this).Instance;
    }
}
@CoreyAlexander
Copy link
Author

After thinking about this a little more, I poked around how the IProvide<> interface worked.
If I switch over to an interface like:

public interface IHaveAutoload<T> {
    T Instance();
}

Things appear to build correctly. I think it is because it's a method now and not an Auto-Property but I'm not sure.

@jolexxa
Copy link
Member

jolexxa commented Jan 16, 2024

Ah, thank you for filing this issue. Seems the method can be used as a workaround in the meantime. I have some ideas on how this might be fixed, will try when I get a chance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants