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

UnitOf(typeof(MyParsable),ParseMethod) requires the members of IUtf8SpanParsable #52

Open
takeisit opened this issue Aug 1, 2024 · 0 comments

Comments

@takeisit
Copy link

takeisit commented Aug 1, 2024

.NET8
UnitGenerator 1.6.2

Hi,

    public readonly struct MyParsable : IParsable<MyParsable>
    {
        public static MyParsable Parse(string s)
            => throw new NotImplementedException();

        public static bool TryParse([NotNullWhen(true)] string? s, [MaybeNullWhen(false)] out MyParsable result)
            => throw new NotImplementedException();

        public static MyParsable Parse(string s, IFormatProvider? provider)
            => throw new NotImplementedException();

        public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out MyParsable result)
            => throw new NotImplementedException();
    }

    [UnitOf(typeof(MyParsable), UnitGenerateOptions.ParseMethod)]
    public readonly partial struct StructInOtherLib
    {
        public static void Test()
            => StructInOtherLib.Parse("");
    }

outputs the followings:

1>------ Build started: Project: OtherLib, Configuration: Debug Any CPU ------
1>xxxx\ConsoleApp10\OtherLib\obj\Debug\net8.0\UnitGenerator\UnitGenerator.SourceGenerator\OtherLib.StructInOtherLib.g.cs(125,67,125,75): error CS1503: Argument 1: cannot convert from 'System.ReadOnlySpan<byte>' to 'string'
1>xxxx\ConsoleApp10\OtherLib\obj\Debug\net8.0\UnitGenerator\UnitGenerator.SourceGenerator\OtherLib.StructInOtherLib.g.cs(130,46,130,54): error CS1503: Argument 1: cannot convert from 'System.ReadOnlySpan<byte>' to 'string?'
1>Done building project "OtherLib.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

Is the following code correct?

public bool HasUtf8SpanParsableInterface() => ReferenceSymbols.ParsableInterface != null && IsImplementedGenericSelfType(ReferenceSymbols.ParsableInterface);

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

No branches or pull requests

1 participant