-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Describe the bug 🐞
When using SplatRegistrations.Register<T>() with a key from a static class in a different namespace, the source generator fails to include the required using directive in the generated code, resulting in a compilation error.
Step to reproduce
-
Define a static class
Keysin namespaceNS1:namespace ConsoleApp2.NS1 { public static class Keys { public static string Key1 = "Key1"; public static string Key2 = "Key2"; } }
-
In a different namespace (
NS2), useSplatRegistrations.RegisterwithKeys.Key1:using ConsoleApp2.NS1; using Splat; namespace ConsoleApp2.NS2 { public class Class1 { static Class1() { SplatRegistrations.Register<Class1>(Keys.Key1); } } }
-
Build the project.
Reproduction repository
https://github.com/reactiveui/ReactiveUI
Expected behavior
The source generator should include the necessary using ConsoleApp2.NS1; directive in the generated file, or fully qualify the reference to Keys.Key1, allowing the project to compile successfully.
Screenshots 🖼️
The generated file Splat.DI.Reg.g.cs contains an unresolved reference to Keys.Key1, causing a compilation error:
error CS0103: The name 'Keys' does not exist in the current context
Generated code snippet (with the issue):
static partial void SetupIOCInternal(Splat.IDependencyResolver resolver)
{
resolver.Register<global::ConsoleApp2.NS2.Class1>(() => new global::ConsoleApp2.NS2.Class1(), Keys.Key1);
}IDE
Visual Studio 2022
Operating system
No response
Version
No response
Device
No response
ReactiveUI Version
No response
Additional information ℹ️
<ItemGroup>
<PackageReference Include="Splat" Version="19.2.1" />
<PackageReference Include="Splat.DependencyInjection.SourceGenerator" Version="2.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>The issue appears to be that the source generator does not preserve or include the namespace of static classes referenced as registration keys, leading to missing using statements in the generated file.