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

Missing handling for BoundConversion in GetAwaitExpressionInfo #54298

Closed
bernd5 opened this issue Jun 22, 2021 · 0 comments · Fixed by #54296
Closed

Missing handling for BoundConversion in GetAwaitExpressionInfo #54298

bernd5 opened this issue Jun 22, 2021 · 0 comments · Fixed by #54296
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@bernd5
Copy link
Contributor

bernd5 commented Jun 22, 2021

Version Used: 80b8a9b

Steps to Reproduce:

compile and run:

using System;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;


var text = @"
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

MyAwaitable Get()
{
    return new MyAwaitable();
}

var x = Get();
x.SetValue(42);

Console.WriteLine(await x + ""!"");

struct MyAwaitable
{
    private ValueTask<int> task;
    private TaskCompletionSource<int> source;

    private TaskCompletionSource<int> Source
    {
        get
        {
            if (source == null)
            {
                source = new TaskCompletionSource<int>();
                task = new ValueTask<int>(source.Task);
            }
            return source;
        }
    }
    internal ValueTask<int> Task
    {
        get
        {
            _ = Source;
            return task;
        }
    }

    public void SetValue(int i)
    {
        Source.SetResult(i);
    }
}

static class MyAwaitableExtension
{
    public static System.Runtime.CompilerServices.ValueTaskAwaiter<int> GetAwaiter(this MyAwaitable a)
    {
        return a.Task.GetAwaiter();
    }
}
";

var tree = SyntaxTree(ParseCompilationUnit(text));

var refApis = AppDomain.CurrentDomain.GetAssemblies().Select(a => MetadataReference.CreateFromFile(a.Location));
var com = CSharpCompilation.Create("something", new []{ tree }, refApis );

var diag =com.GetDiagnostics().Where(e => e.Severity == DiagnosticSeverity.Error).ToList();

foreach(var d in diag)
{
  Console.WriteLine(d);    
}

var model = com.GetSemanticModel(tree);
var awaitExpression = tree.GetRoot().DescendantNodes().OfType<AwaitExpressionSyntax>().First();
var awaitInfo = model.GetAwaitExpressionInfo(awaitExpression);

Console.WriteLine(awaitInfo.GetAwaiterMethod == null);

Expected Behavior:
Roslyn should find / return the GetAwaiterMethod - it should print False.

Actual Behavior:
GetAwaiterMethod is null - it prints True

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 22, 2021
AlekseyTs pushed a commit that referenced this issue Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant