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

[CodePlex] Bug in SemanticModel.GetAwaitExpressionInfo and expression lambdas #323

Closed
gafter opened this issue Feb 9, 2015 · 2 comments · Fixed by #326
Closed

[CodePlex] Bug in SemanticModel.GetAwaitExpressionInfo and expression lambdas #323

gafter opened this issue Feb 9, 2015 · 2 comments · Fixed by #326
Assignees
Labels
Area-Compilers Bug Language-C# Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented Verified
Milestone

Comments

@gafter
Copy link
Member

gafter commented Feb 9, 2015

@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 to Action. However, if the type of f is changed to Func<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");
        }
    }
}
@gafter gafter self-assigned this Feb 9, 2015
@gafter gafter added this to the 1.0 (stable) milestone Feb 9, 2015
gafter added a commit to gafter/roslyn that referenced this issue Feb 9, 2015
… expression used as an expression statement.
jaredpar added a commit that referenced this issue Feb 9, 2015
Fix #323 bug in SemanticModel.GetAwaitExpressionInfo when await expression used as an expression statement.
@gafter gafter assigned theoy and unassigned gafter Feb 10, 2015
@gafter
Copy link
Member Author

gafter commented Feb 18, 2015

@erik-kallen your bug originally

@gafter gafter added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Mar 4, 2015
@gafter gafter assigned jaredpar and unassigned theoy Mar 9, 2015
@gafter
Copy link
Member Author

gafter commented Mar 9, 2015

@jaredpar You pulled my pull request, so I'm going to punish you by asking you to verify that this bug is fixed, please 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Language-C# Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented Verified
Projects
None yet
4 participants