Skip to content

[Bug]: SPLATDI001 error on call to non-Splat Register() method #282

@cbordeman

Description

@cbordeman

Describe the bug 🐞

This is easily reproducible:

using Avalonia.Controls;
namespace ClassLibrary1;
public class Class1
{
    public void Blah<TViewModel, TView>()
        where TView : Control
    {
        ShadUI.DialogManager dm1 = new();
        dm1.Register<TView, TViewModel>();
    }
}

On the call to Register(), I'm getting a compile error:
[SPLATDI001] TViewModel has more than one constructor and one hasn't been marked with DependencyInjectionConstructorAttribute

If the TView type constraint is removed, the error goes away, but that could be because the method call doesn't compile. Here is the ShadUI method I am calling:

public DialogManager Register<TView, TContext>() where TView : Control
{
    this.CustomDialogs.Add(typeof (TContext), typeof (TView));
    return this;
}

I'm sure the code generator shouldn't pick this up. Is it seeing a "Register<T, T2>() method and just assuming it's a Splat Register call? If so, is there a way to prevent this? This is a very common prototype in a lot of code bases.

I've put the code in a repo: https://github.com/cbordeman/Splat-CodeGen-Bug

Step to reproduce

Open the repo and wait a few seconds, or invoke a build.

Reproduction repository

https://github.com/cbordeman/Splat-CodeGen-Bug

Expected behavior

No compile error.

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions