genaray / Arch.Extended

Extensions for Arch with some useful features like Systems, Source Generator and Utils.
Apache License 2.0
151 stars 35 forks source link

Query source generation compile error #32

Closed Exanite closed 11 months ago

Exanite commented 11 months ago

Issue I'm getting a compile "error" with the query source generation. It strangely doesn't prevent me from building and running the project, but it does prevent hot reloading. (See comment below) image

I'm using Arch.System.SourceGenerator v1.1.2:

<PackageReference Include="Arch.System.SourceGenerator" Version="1.1.2" />

Potential cause This appears to be because the generated code does not include the correct using statement nor does it use the global:: keyword to fully specify which type to use: image image

Workaround Fully qualifying the name in the source code fixes the error: image image

This implies that the source generator is directly using the type name from the source code.

Potential fix I'm interested in taking a look at the source generator code and changing it so that the global:: qualified type name is always used. This should prevent any similar issues in the future and prevent type name collisions.

However, I'm not familiar with C#'s source generation feature and what it's limitations are.

Exanite commented 11 months ago

I'm not sure why, but after some testing, the generated code is now including the namespace in the type name: image

I'm also getting a similar result with my original project's SpriteBatch. The generated code now correctly uses Microsoft.Xna.Framework.Graphics.SpriteBatch instead of SpriteBatch.

This is in a new project with the following references:

<ItemGroup>
    <PackageReference Include="Arch" Version="1.2.6.8-alpha" />
    <PackageReference Include="Arch.EventBus" Version="1.0.2" />
    <PackageReference Include="Arch.LowLevel" Version="1.0.3" />
    <PackageReference Include="Arch.Persistence" Version="1.0.2" />
    <PackageReference Include="Arch.Relationships" Version="1.0.1" />
    <PackageReference Include="Arch.System" Version="1.0.2" />
    <PackageReference Include="Arch.System.SourceGenerator" Version="1.1.2" />
</ItemGroup>

This fixes the original issue I was having, but I'm now confused as to why I originally had the error.

Exanite commented 11 months ago

Everything seems fine now, but if anyone knows why I had the original issue (namespace of type not included in source generation), I would greatly appreciate it.

Edit: I'm suspecting my original issue was due to Rider incorrectly caching certain outputs. Unloading and reloading the project seems to fix it. It's a bit hard to verify though because this issue happens very rarely.

In any case, it's not a problem with Arch's source generator.