UnitGenerator icon indicating copy to clipboard operation
UnitGenerator copied to clipboard

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

Open takeisit opened this issue 1 year ago • 0 comments

.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? https://github.com/Cysharp/UnitGenerator/blob/4c074f11d0ee441d066efa28861789b7e244c8dd/src/UnitGenerator/SourceGenerator.cs#L1256

takeisit avatar Aug 01 '24 12:08 takeisit