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 ?. with extension method produces invalid code #79

Closed
persn opened this issue Jun 20, 2024 · 1 comment
Closed

Combining ?. with extension method produces invalid code #79

persn opened this issue Jun 20, 2024 · 1 comment

Comments

@persn
Copy link

persn commented Jun 20, 2024

The following code

    internal partial class Class17
    {
        [Zomp.SyncMethodGenerator.CreateSyncVersion(OmitNullableDirective = true)]
        public async Task FooAsync()
        {
            var bar = new Bar2();
            var delay = bar?.GetInt() ?? 0;
            await Task.Delay(delay);
        }
    }

    internal class Bar2
    {
    }

    internal static class Bar2Extensions
    {
        public static int GetInt(this Bar2 bar2) => 0;
    }

Produces the following

        public void Foo()
        {
            var bar = new global::ClassLibrary1.Bar2();
            var delay = (!bar.HasValue?(int?)null: global::ClassLibrary1.Bar2Extensions.GetInt(bar))?? 0;
            global::System.Threading.Thread.Sleep(delay);
        }

The class Bar2 doesn't have a HasValue method so this produces compile fails

error CS1061: 'Bar2' does not contain a definition for 'HasValue' and no accessible extension method 'HasValue' accepting a first argument of type 'Bar2' could be found (are you missing a using directive or an assembly reference?)
warning CS8603: Possible null reference return.
@virzak
Copy link
Contributor

virzak commented Jun 27, 2024

Reproduced. Will fix this weekend.

@virzak virzak closed this as completed in a1c0e95 Jul 6, 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

No branches or pull requests

2 participants