未验证 提交 4d749695 编写于 作者: R Rikki Gibson 提交者: GitHub

Fix TakeIncrementalSnapshot crash (#38752)

上级 712a1ca8
......@@ -5786,6 +5786,9 @@ public override BoundNode VisitAssignmentOperator(BoundAssignmentOperator node)
var left = node.Left;
var right = node.Right;
VisitLValue(left);
// we may enter a conditional state for error scenarios on the LHS.
Unsplit();
FlowAnalysisAnnotations leftAnnotations = GetLValueAnnotations(left);
TypeWithAnnotations declaredType = LvalueResultType;
TypeWithAnnotations leftLValueType = ApplyLValueAnnotations(declaredType, leftAnnotations);
......
......@@ -104672,6 +104672,66 @@ public class Broken<T> : IEnumerable<IEquatable<T>> where T : class
comp.VerifyDiagnostics();
}
[Fact, WorkItem(37868, "https://github.com/dotnet/roslyn/issues/37868")]
public void IsPatternVariableDeclaration_LeftOfAssignmentOperator()
{
var source = @"
using System;
class C
{
void Test1()
{
if (unknown is string b = )
{
Console.WriteLine(b);
}
}
void Test2(bool a)
{
if (a is bool (b = a))
{
Console.WriteLine(b);
}
}
}
";
var comp = CreateNullableCompilation(source);
comp.VerifyDiagnostics(
// (8,13): error CS0103: The name 'unknown' does not exist in the current context
// if (unknown is string b = )
Diagnostic(ErrorCode.ERR_NameNotInContext, "unknown").WithArguments("unknown").WithLocation(8, 13),
// (8,35): error CS1525: Invalid expression term ')'
// if (unknown is string b = )
Diagnostic(ErrorCode.ERR_InvalidExprTerm, ")").WithArguments(")").WithLocation(8, 35),
// (10,31): error CS0165: Use of unassigned local variable 'b'
// Console.WriteLine(b);
Diagnostic(ErrorCode.ERR_UseDefViolation, "b").WithArguments("b").WithLocation(10, 31),
// (16,23): error CS8129: No suitable 'Deconstruct' instance or extension method was found for type 'bool', with 1 out parameters and a void return type.
// if (a is bool (b = a))
Diagnostic(ErrorCode.ERR_MissingDeconstruct, "(b ").WithArguments("bool", "1").WithLocation(16, 23),
// (16,24): error CS0103: The name 'b' does not exist in the current context
// if (a is bool (b = a))
Diagnostic(ErrorCode.ERR_NameNotInContext, "b").WithArguments("b").WithLocation(16, 24),
// (16,26): error CS1026: ) expected
// if (a is bool (b = a))
Diagnostic(ErrorCode.ERR_CloseParenExpected, "=").WithLocation(16, 26),
// (16,30): error CS1525: Invalid expression term ')'
// if (a is bool (b = a))
Diagnostic(ErrorCode.ERR_InvalidExprTerm, ")").WithArguments(")").WithLocation(16, 30),
// (16,30): error CS1002: ; expected
// if (a is bool (b = a))
Diagnostic(ErrorCode.ERR_SemicolonExpected, ")").WithLocation(16, 30),
// (16,30): error CS1513: } expected
// if (a is bool (b = a))
Diagnostic(ErrorCode.ERR_RbraceExpected, ")").WithLocation(16, 30),
// (18,31): error CS0103: The name 'b' does not exist in the current context
// Console.WriteLine(b);
Diagnostic(ErrorCode.ERR_NameNotInContext, "b").WithArguments("b").WithLocation(18, 31));
}
[WorkItem(30140, "https://github.com/dotnet/roslyn/issues/30140")]
[Fact]
public void NullCoalescingAssignment_UseInExpression()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册