提交 910b55b2 编写于 作者: N Neal Gafter

Add a test for delegate creation expression containing broken lambda

to ensure that we bind the lambda for intellisense purposes.
I also hand-tested the scenario of #4480 to reproduce it on VS2015
and to verify that the problem does not occur on the master branch.
Fixes #4480
上级 189e9828
......@@ -1737,6 +1737,49 @@ class C { C() { Unbound2.Select(x => Unbound1); } }";
Diagnostic(ErrorCode.ERR_NameNotInContext, "Unbound1").WithArguments("Unbound1").WithLocation(2, 38)
);
}
[Fact]
[WorkItem(4480, "https://github.com/dotnet/roslyn/issues/4480")]
public void TestLambdaWithError06()
{
var source =
@"class Program
{
static void Main(string[] args)
{
// completion should work even in a syntactically invalid lambda
var handler = new MyDelegateType((s, e) => { e. });
}
}
public delegate void MyDelegateType(
object sender,
MyArgumentType e
);
public class MyArgumentType
{
public int SomePublicMember;
}";
var compilation = CreateCompilationWithMscorlibAndSystemCore(source)
.VerifyDiagnostics(
// var handler = new MyDelegateType((s, e) => { e. });
Diagnostic(ErrorCode.ERR_IdentifierExpected, "}").WithLocation(6, 57),
// (6,57): error CS1002: ; expected
// var handler = new MyDelegateType((s, e) => { e. });
Diagnostic(ErrorCode.ERR_SemicolonExpected, "}").WithLocation(6, 57)
)
;
var tree = compilation.SyntaxTrees[0];
var sm = compilation.GetSemanticModel(tree);
var lambda = tree.GetCompilationUnitRoot().DescendantNodes().OfType<LambdaExpressionSyntax>().Single();
var eReference = lambda.Body.DescendantNodes().OfType<IdentifierNameSyntax>().First();
Assert.Equal("e", eReference.ToString());
var typeInfo = sm.GetTypeInfo(eReference);
Assert.Equal("MyArgumentType", typeInfo.Type.Name);
Assert.Equal(TypeKind.Class, typeInfo.Type.TypeKind);
Assert.NotEmpty(typeInfo.Type.GetMembers("SomePublicMember"));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册