dotnet/roslyn

Semantic model: Should GetSymbolInfo on `var _` return an IDiscardSymbol?

Open

#16,316 创建于 2017年1月7日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)C# (4,257 fork)batch import
Area-CompilersFeature - TuplesFeature Requesthelp wanted

仓库指标

Star
 (20,414 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

Currently, GetSymbolInfo will return null in this case. The only scenario where a discard symbol is returned is with the _ identifier/expression.

   [Fact]
        public void VariousDiscardsInForeach()
        {
            var source =
@"
class C
{
    static void Main()
    {
        foreach ((var _, int _, _, var (_, _), int x) in new[] { (1L, 2, 3, (""hello"", 5), 6) })
        {
            System.Console.Write(x);
        }
    }
}
";
            var comp = CreateCompilationWithMscorlib(source, options: TestOptions.DebugExe, references: s_valueTupleRefs);
            var tree = comp.SyntaxTrees.First();
            var model = comp.GetSemanticModel(tree);

            var discard1 = GetDiscardDesignations(tree).First();
            Assert.Null(model.GetSymbolInfo(declaration1).Symbol); // should return a discard symbol instead?
        }

FYI @AlekseyTs @gafter Related to https://github.com/dotnet/roslyn/pull/16153

贡献者指南