未验证 提交 be77888b 编写于 作者: J Julien Couvreur 提交者: GitHub

Self-referencing const via lambda should not cause overflow (#24876)

上级 4a2df32f
......@@ -201,9 +201,9 @@ public override void VisitLocal(ILocalSymbol symbol)
builder.Add(CreatePart(SymbolDisplayPartKind.LocalName, symbol, symbol.Name));
if (symbol.IsConst &&
if (format.LocalOptions.IncludesOption(SymbolDisplayLocalOptions.IncludeConstantValue) &&
symbol.IsConst &&
symbol.HasConstantValue &&
format.LocalOptions.IncludesOption(SymbolDisplayLocalOptions.IncludeConstantValue) &&
CanAddConstant(symbol.Type, symbol.ConstantValue))
{
AddSpace();
......
......@@ -2977,8 +2977,52 @@ static void Main(string[] args)
// case (object)"b":
Diagnostic(ErrorCode.ERR_ConstantExpected, @"(object)""b""").WithLocation(23, 18));
}
[Fact]
[WorkItem(24869, "https://github.com/dotnet/roslyn/issues/24869")]
public void TestSelfReferencingViaLambda()
{
string source = @"
using System.Collections.Generic;
using System.Linq;
class C
{
static void F(IEnumerable<C> c)
{
const int F =
c.Select(o => new { E = F });
}
}";
var comp = CreateStandardCompilation(source, references: new[] { LinqAssemblyRef });
comp.VerifyDiagnostics(
// (9,9): error CS0029: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<<anonymous type: int E>>' to 'int'
// c.Select(o => new { E = F });
Diagnostic(ErrorCode.ERR_NoImplicitConv, "c.Select(o => new { E = F })").WithArguments("System.Collections.Generic.IEnumerable<<anonymous type: int E>>", "int").WithLocation(9, 9)
);
}
[Fact]
[WorkItem(24869, "https://github.com/dotnet/roslyn/issues/24869")]
public void TestSelfReferencingViaLambda2()
{
string source = @"
using System.Collections.Generic;
using System.Linq;
class C
{
static void F(IEnumerable<C> c)
{
const int F = c.Sum(o => F);
}
}";
var comp = CreateStandardCompilation(source, references: new[] { LinqAssemblyRef });
comp.VerifyDiagnostics(
// (8,34): error CS0110: The evaluation of the constant value for 'F' involves a circular definition
// const int F = c.Sum(o => F);
Diagnostic(ErrorCode.ERR_CircConstValue, "F").WithArguments("F").WithLocation(8, 34)
);
}
}
internal sealed class BoundTreeSequencer : BoundTreeWalkerWithStackGuard
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册