提交 ab544702 编写于 作者: R Rikki Gibson

Fix test gap and delete outdated prototype comment

上级 99c25e68
......@@ -971,9 +971,6 @@ internal override bool HasSpecialName
internal sealed override bool IsDirectlyExcludedFromCodeCoverage =>
GetDecodedWellKnownAttributeData()?.HasExcludeFromCodeCoverageAttribute == true;
// PROTOTYPE(local-function-attributes): security-related properties perhaps should be
// overridden in SynthesizedMethodBaseSymbol in order to work with local functions
internal override bool RequiresSecurityObject
{
get
......
......@@ -370,7 +370,8 @@ static void M()
[InlineData("[return: A] void local() { }")]
[InlineData("void local([A] int i) { }")]
[InlineData("void local<[A]T>() {}")]
public void LocalFunctionAttribute_SpeculativeSemanticModel(string localFunction)
[InlineData("[A] int x = 123;")]
public void LocalFunctionAttribute_SpeculativeSemanticModel(string statement)
{
string text = $@"
using System;
......@@ -380,7 +381,7 @@ class C
{{
static void M()
{{
{localFunction}
{statement}
}}
}}";
var tree = SyntaxFactory.ParseSyntaxTree(text);
......@@ -410,6 +411,58 @@ static void M()
Assert.Equal(attrType, info.Symbol);
}
[Theory]
[InlineData(@"[Attr(42, Name = ""hello"")] void local() { }")]
[InlineData(@"[return: Attr(42, Name = ""hello"")] void local() { }")]
[InlineData(@"void local([Attr(42, Name = ""hello"")] int i) { }")]
[InlineData(@"void local<[Attr(42, Name = ""hello"")]T>() {}")]
[InlineData(@"[Attr(42, Name = ""hello"")] int x = 123;")]
public void LocalFunctionAttribute_Argument_SemanticModel(string statement)
{
var text = $@"
class Attr
{{
public Attr(int id) {{ }}
public string Name {{ get; set; }}
}}
class C
{{
static void M()
{{
{statement}
}}
}}";
var tree = SyntaxFactory.ParseSyntaxTree(text, options: TestOptions.RegularPreview);
var comp = CreateCompilation(tree);
var model = comp.GetSemanticModel(tree, ignoreAccessibility: true);
validate(model, tree);
var newTree = SyntaxFactory.ParseSyntaxTree(text + " ", options: TestOptions.RegularPreview);
var mMethod = (MethodDeclarationSyntax)newTree.FindNodeOrTokenByKind(SyntaxKind.MethodDeclaration, occurrence: 1).AsNode();
Assert.True(model.TryGetSpeculativeSemanticModelForMethodBody(mMethod.Body.SpanStart, mMethod, out var newModel));
validate(newModel, newTree);
static void validate(SemanticModel model, SyntaxTree tree)
{
var attributeSyntax = tree.GetRoot().DescendantNodes().OfType<AttributeSyntax>().Single();
var attrArgs = attributeSyntax.ArgumentList.Arguments;
var attrArg0 = attrArgs[0].Expression;
Assert.Null(model.GetSymbolInfo(attrArg0).Symbol);
var argType0 = model.GetTypeInfo(attrArg0).Type;
Assert.Equal(SpecialType.System_Int32, argType0.SpecialType);
var attrArg1 = attrArgs[1].Expression;
Assert.Null(model.GetSymbolInfo(attrArg1).Symbol);
var argType1 = model.GetTypeInfo(attrArg1).Type;
Assert.Equal(SpecialType.System_String, argType1.SpecialType);
}
}
[Fact]
public void LocalFunctionAttribute_OnFunction()
{
......
......@@ -1066,6 +1066,35 @@ static void local1(int z)
Assert.Contains("System.Int32 y", lookupSymbols);
}
[Fact]
public void LookupInsideIncompleteStatementAttribute()
{
var testSrc = @"
using System;
class Program
{
const int w = 0451;
void M()
{
int x = 42;
const int y = 123;
[ObsoleteAttribute(/*pos*/
int
}
}
";
var lookupNames = GetLookupNames(testSrc);
var lookupSymbols = GetLookupSymbols(testSrc).Select(e => e.ToTestDisplayString()).ToList();
Assert.Contains("w", lookupNames);
Assert.Contains("y", lookupNames);
Assert.Contains("System.Int32 Program.w", lookupSymbols);
Assert.Contains("System.Int32 y", lookupSymbols);
}
[WorkItem(541909, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541909")]
[Fact]
public void LookupFromRangeVariableAfterFromClause()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册