Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Generator fails for types in a "OneOf" namespace #174

Open
StefanLochauMF opened this issue Jun 24, 2024 · 0 comments · May be fixed by #175
Open

Source Generator fails for types in a "OneOf" namespace #174

StefanLochauMF opened this issue Jun 24, 2024 · 0 comments · May be fixed by #175

Comments

@StefanLochauMF
Copy link

StefanLochauMF commented Jun 24, 2024

When defining a type inheriting a OneOfBase<T,...> with the [GenerateOneOf] attribute inside a namespace that contains "OneOf" as a segment, the generator fails.

User code:

namespace MyLibrary.OneOf.Extensions;

[GenerateOneOf]
public sealed partial class OneOf1 : OneOfBase<object>;

Generates:

// <auto-generated />
#pragma warning disable 1591

namespace MyLibrary.OneOf.Extensions
{
    partial class OneOf1
    {
        public OneOf1(OneOf.OneOf<global::MyLibrary.OneOf.Extensions.A> _) : base(_) { }

        public static implicit operator OneOf1(global::MyLibrary.OneOf.Extensions.A _) => new OneOf1(_);
        public static explicit operator global::MyLibrary.OneOf.Extensions.A(OneOf1 _) => _.AsT0;
    }
}

The issue lies with the constructor argument, where the compiler tries to resolve OneOf.OneOf<...> as MyLibrary.OneOf.OneOf<..>.

This could be fixed by adding a global:: in

public {classSymbol.Name}(OneOf.OneOf<{oneOfGenericPart}> _) : base(_) {{ }}

to make it

public {classSymbol.Name}(global::OneOf.OneOf<{oneOfGenericPart}> _) : base(_) {{ }} 
StefanLochauMF added a commit to StefanLochauMF/OneOf that referenced this issue Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant