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

IntelliSense cannot detect IAsyncEnumerable's yield return type when that parameter is used #68027

Closed
datvm opened this issue Apr 29, 2023 · 8 comments · Fixed by #75660
Closed
Assignees
Labels
Area-Compilers Feature Request IntelliSense-Completion Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented Retriage
Milestone

Comments

@datvm
Copy link

datvm commented Apr 29, 2023

Version Used: 4.5.2-3.23171.7 (d17f741)

Steps to Reproduce:

Put in the following code (in this example it's in the top-level Program.cs):

Console.WriteLine("Hello");
_ = BarAsync();

static async IAsyncEnumerable<Foo> BarAsync()
{
    var tmp = new string[10];
    foreach (var item in tmp)
    {
        yield return new(async s =>
        {
            // Happen here
            await Task.CompletedTask;
            throw new NotImplementedException();
        });
    }
}

record Foo(Func<string, Task<string>> func); // Happen to both Func<> and delegate

The code above compiles but at the // Happen here line, any attempt to access s results in s being unknown ? even though without it, the compiler and IntelliSense correctly detect s as string.

Diagnostic Id: N/A

Expected Behavior:

s should maintain its type as string while typing.

Actual Behavior:

Whenever there is an attempt to access s, it becomes ?. This happens to both Visual Studio and VS Code (latest version). If you put in valid code without IntelliSense, it still compiles, for example:

yield return new(async s =>
{
    return s.ToUpper(); // Have to manually type it
    await Task.CompletedTask;
    throw new NotImplementedException();            
});

Correct behavior when s is not being typed:

image

In both VS and VS Code, s becomes unknown when any attempt to access it is made:

image

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 29, 2023
@datvm
Copy link
Author

datvm commented Apr 29, 2023

Attempt to "navigate" around the issue by declaring a variable does not work as well (note that s2 now has type of ?? instead of ?):

image

However this issue does not happen if s2 is explicitly typed, maybe because at this time IntelliSense trusts that the error would be thrown earlier and s2 doesn't need to be guessed:

image

@datvm
Copy link
Author

datvm commented May 15, 2023

Hi any update on this? This is quite annoying to work with because I keep losing code suggestion.

Thanks.

@CyrusNajmabadi
Copy link
Member

@datvm There is no update on this. We would take a community contribution to fix this though, if you were interested :)

@datvm
Copy link
Author

datvm commented May 15, 2023

@CyrusNajmabadi thanks. I hope someone can take a look at this. Unfortunately I am quite unfamiliar with Roslyn so I cannot really help :(

@arunchndr arunchndr added Feature Request and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 22, 2023
@arunchndr arunchndr added this to the 18.0 milestone Aug 22, 2023
@CyrusNajmabadi
Copy link
Member

Moving to compiler. We call into their apis for semantic information.

@jaredpar jaredpar modified the milestones: 18.0, 17.13 Oct 25, 2024
@jcouv jcouv added 4 - In Review A fix for the issue is submitted for review. and removed 3 - Working labels Oct 29, 2024
@jcouv jcouv removed the 4 - In Review A fix for the issue is submitted for review. label Oct 30, 2024
@jcouv
Copy link
Member

jcouv commented Oct 30, 2024

Fix was merged into 17.13p2. Thanks for reporting this issue @datvm !

@jcouv jcouv added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Oct 30, 2024
@datvm
Copy link
Author

datvm commented Oct 31, 2024

@jcouv Thank you and congrats, that's awesome! I assume this issue is not related to #72571 and it's not fixed as a result of this fix then?

@jcouv
Copy link
Member

jcouv commented Oct 31, 2024

I assume this issue is not related to #72571 and it's not fixed as a result of this fix then?

That issue is not related. The issue here, which was fixed, relates to a lambda in a yield return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature Request IntelliSense-Completion Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented Retriage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants