提交 ae3a904e 编写于 作者: N Neal Gafter

Repair missing code in lowering the decision tree.

Fixes #13395
上级 51518fdf
......@@ -279,6 +279,7 @@ private void LowerDecisionTree(DecisionTree.Guarded guarded)
if (guarded.Guard == null || guarded.Guard.ConstantValue == ConstantValue.True)
{
// unconditional
Debug.Assert(guarded.Default == null);
if (guarded.Bindings.IsDefaultOrEmpty)
{
_loweredDecisionTree.Add(_factory.Goto(targetLabel));
......@@ -303,6 +304,8 @@ private void LowerDecisionTree(DecisionTree.Guarded guarded)
var guardFailed = _factory.GenerateLabel("guardFailed");
sectionBuilder.Add(_factory.Goto(guardFailed));
_loweredDecisionTree.Add(_factory.Label(guardFailed));
LowerDecisionTree(guarded.Expression, guarded.Default);
}
}
......
......@@ -1258,5 +1258,45 @@ public static void Main()
var i2Ref = tree.GetCompilationUnitRoot().DescendantNodes().OfType<IdentifierNameSyntax>().Where(n => n.ToString() == "i2").Single();
Assert.Equal("System.Object", model.GetTypeInfo(i2Ref).Type.ToTestDisplayString());
}
[Fact, WorkItem(13395, "https://github.com/dotnet/roslyn/issues/13395")]
public void CodeGenSwitchInLoop()
{
var source =
@"using System;
class Program
{
public static void Main(string[] args)
{
bool hasB = false;
foreach (var c in ""ab"")
{
switch (c)
{
case char b when IsB(b):
hasB = true;
break;
default:
hasB = false;
break;
}
}
Console.WriteLine(hasB);
}
public static bool IsB(char value)
{
return value == 'b';
}
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe);
compilation.VerifyDiagnostics();
var expectedOutput =
@"True";
var comp = CompileAndVerify(compilation, expectedOutput: expectedOutput);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册