-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersBugLanguage-C#Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implementedVerified
Milestone
Description
@erik-kallen reported: in http://roslyn.codeplex.com/workitem/400
The following program will output
FAILURE, even though the program is valid and no diagnostics messages are reported (using 1.0-beta). It will also fail if the type of f is changed toAction. However, if the type offis changed toFunc<Task<int>>, there is no problem.
using System;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace RoslynTest {
class Program {
static void Main(string[] args) {
var syntaxTree = CSharpSyntaxTree.ParseText(@"
using System;
using System.Threading.Tasks;
public class C {
public C() {
Task<int> task = null;
Func<Task> f = async() => await task;
}
}");
var compilation = CSharpCompilation.Create("Test", new[] { syntaxTree }, new[] { MetadataReference.CreateFromAssembly(typeof(object).Assembly), MetadataReference.CreateFromAssembly(typeof(Enumerable).Assembly) }, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
foreach (var d in compilation.GetDiagnostics())
Console.WriteLine(d.GetMessage());
var semanticModel = compilation.GetSemanticModel(syntaxTree);
var root = syntaxTree.GetRoot();
var expr = root.DescendantNodes().OfType<ConstructorDeclarationSyntax>().First().Body.Statements.OfType<LocalDeclarationStatementSyntax>().ElementAt(1).Declaration.Variables[0].Initializer.Value;
var awaitExpr = expr.DescendantNodes().OfType<AwaitExpressionSyntax>().Single();
var awaitInfo = semanticModel.GetAwaitExpressionInfo(awaitExpr);
if (awaitInfo.GetAwaiterMethod != null)
Console.WriteLine("Everything was OK");
else
Console.WriteLine("FAILURE: GetAwaitExpressionInfo returned missing data even though the program is valid");
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersBugLanguage-C#Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implementedVerified