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
Version Used: 80b8a9b
Steps to Reproduce:
compile and run:
Expected Behavior:
Roslyn should find / return the
GetAwaiterMethod- it should printFalse.Actual Behavior:
GetAwaiterMethodis null - it printsTrue