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

Combining ?. operator with extension method and generics #89

Open
persn opened this issue Dec 12, 2024 · 0 comments
Open

Combining ?. operator with extension method and generics #89

persn opened this issue Dec 12, 2024 · 0 comments

Comments

@persn
Copy link

persn commented Dec 12, 2024

Consider the following piece of code

    internal partial class TestZomp
    {
        [Zomp.SyncMethodGenerator.CreateSyncVersion]
        public async Task Foo1Async()
        {
            _ = Singleton.Foo?.Get<string>();
            await Task.Delay(100);
        }
    }

    internal class Singleton
    {
        public static Foo Foo { get; set; }
    }

    internal class Foo {}

    internal static class FooExtensions
    {
        public static T Get<T>(this Foo foo) => default;
    }

It generates

        public void Foo1()
        {
            _ = ((global::System.Func<global::Sandbox.Foo?,string?>)((param)=>(object?)param == null ? (string?)null : global::Sandbox.FooExtensions.Get(param)))(global::Sandbox.Singleton.Foo);
            global::System.Threading.Thread.Sleep(100);
        }

Which fails because <string> is missing for the Get call

error CS0411: The type arguments for method 'FooExtensions.Get<T>(Foo)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
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