提交 9dff70d0 编写于 作者: A AlekseyTs

Do not mark BoundBlock associated with ArrowExpressionClause as compiler...

Do not mark BoundBlock associated with ArrowExpressionClause as compiler generated. This ensures SemanticModel does proper caching for this node. (changeset 1362639)
上级 890d15f9
......@@ -3220,7 +3220,7 @@ private static bool IsValidStatementExpression(CSharpSyntaxNode syntax, BoundExp
}
// Need to attach the tree for when we generate sequence points.
return new BoundBlock(node, locals, ImmutableArray.Create(statement)) { WasCompilerGenerated = true };
return new BoundBlock(node, locals, ImmutableArray.Create(statement)) { WasCompilerGenerated = node.Kind != SyntaxKind.ArrowExpressionClause };
}
/// <summary>
......
......@@ -11,7 +11,7 @@ internal sealed partial class LocalRewriter
{
public override BoundNode VisitBlock(BoundBlock node)
{
if (node.WasCompilerGenerated || !this.GenerateDebugInfo)
if (node.WasCompilerGenerated || !this.GenerateDebugInfo || node.Syntax.Kind == SyntaxKind.ArrowExpressionClause)
{
return node.Update(node.Locals, VisitList(node.Statements));
}
......
......@@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.CSharp.UnitTests;
using Roslyn.Test.Utilities;
using System.Linq;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests.Semantics
......@@ -304,5 +305,27 @@ static void Main()
CompileAndVerify(source, expectedOutput: "GetAction 1");
}
[Fact, WorkItem(1069421, "DevDiv")]
public void Bug1069421()
{
var comp = CreateCompilationWithMscorlib45(@"
class Program
{
private int x => () => {
}
");
var tree = comp.SyntaxTrees[0];
var model = comp.GetSemanticModel(tree);
var node = tree.GetRoot().DescendantNodes().OfType<ParenthesizedLambdaExpressionSyntax>().Single();
var typeInfo1 = model.GetTypeInfo(node);
var typeInfo2 = model.GetTypeInfo(node);
Assert.Equal(typeInfo1.Type, typeInfo2.Type);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册