Skip to content

Missing handling for BoundConversion in GetAwaitExpressionInfo #54298

@bernd5

Description

@bernd5

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersuntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions