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

Fix GetSymbolInfo on ValueTuple declaration #43467

Merged
merged 7 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ private MemberSemanticModel CreateMemberModel(CSharpSyntaxNode node)
case SyntaxKind.VariableDeclarator:
{
var variableDecl = (VariableDeclaratorSyntax)node.Parent;
SourceMemberFieldSymbol fieldSymbol = GetDeclaredFieldSymbol(variableDecl);
FieldSymbol fieldSymbol = GetDeclaredFieldSymbol(variableDecl);

return InitializerSemanticModel.Create(
this,
Expand Down Expand Up @@ -1194,7 +1194,7 @@ private AttributeSemanticModel CreateModelForAttribute(Binder enclosingBinder, A
containingModel?.GetRemappedSymbols());
}

private SourceMemberFieldSymbol GetDeclaredFieldSymbol(VariableDeclaratorSyntax variableDecl)
private FieldSymbol GetDeclaredFieldSymbol(VariableDeclaratorSyntax variableDecl)
{
var declaredSymbol = GetDeclaredSymbol(variableDecl);

Expand All @@ -1203,10 +1203,10 @@ private SourceMemberFieldSymbol GetDeclaredFieldSymbol(VariableDeclaratorSyntax
switch (variableDecl.Parent.Parent.Kind())
{
case SyntaxKind.FieldDeclaration:
return declaredSymbol.GetSymbol<SourceMemberFieldSymbol>();
return declaredSymbol.GetSymbol<FieldSymbol>();

case SyntaxKind.EventFieldDeclaration:
return (SourceMemberFieldSymbol)(declaredSymbol.GetSymbol<EventSymbol>()).AssociatedField;
return (declaredSymbol.GetSymbol<EventSymbol>()).AssociatedField;
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26756,5 +26756,29 @@ private void Method(IInterface inter, Func<(Type, Type), string> keySelector)
var comp2 = CreateCompilation(source1, references: new[] { comp1.EmitToImageReference() }, options: TestOptions.DebugDll);
CompileAndVerify(comp2);
}

[Fact]
[WorkItem(1090920, "https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/1090920")]
public void GetSymbolInfoOnInitializerOfValueTupleField()
{

var source = @"
namespace System
{
public struct ValueTuple<T1>
{
public T1 Item1 = default;
public ValueTuple(T1 item1) { }
}
}
";

var comp = CreateCompilation(new[] { source }, options: TestOptions.DebugDll);

var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree, ignoreAccessibility: false);
var literal = tree.GetRoot().DescendantNodes().OfType<LiteralExpressionSyntax>().Single();
Assert.True(model.GetSymbolInfo(literal).IsEmpty);
}
}
}