未验证 提交 8f95040b 编写于 作者: C Charles Stoner 提交者: GitHub

Minor cleanup for nullable (#33604)

上级 5d671959
......@@ -3751,11 +3751,10 @@ private bool HasTopLevelNullabilityConversion(TypeSymbolWithAnnotations source,
{
var lambda = (BoundLambda)operandOpt;
var delegateType = targetType.GetDelegateType();
var methodSignatureOpt = lambda.UnboundLambda.HasExplicitlyTypedParameterList ? null : delegateType?.DelegateInvokeMethod;
var unboundLambda = lambda.UnboundLambda;
var methodSignatureOpt = unboundLambda.HasExplicitlyTypedParameterList ? null : delegateType?.DelegateInvokeMethod;
var variableState = GetVariableState();
Analyze(compilation, lambda, Diagnostics, delegateInvokeMethod: delegateType?.DelegateInvokeMethod, returnTypes: null, initialState: variableState);
var unboundLambda = GetUnboundLambda(lambda, variableState);
var boundLambda = unboundLambda.Bind(delegateType);
if (reportRemainingWarnings)
{
ReportNullabilityMismatchWithTargetDelegate(node.Syntax, delegateType, unboundLambda);
......
......@@ -591,8 +591,6 @@ private static bool IsTypeLessVisibleThan(TypeSymbol type, Symbol sym, ref HashS
/// completes without the predicate returning true for any type, this method returns null.
/// </summary>
public static TypeSymbol VisitType<T>(
// https://github.com/dotnet/roslyn/issues/30059: If TypeSymbolWithAnnotations
// is a struct, use a single type argument and a single predicate.
this TypeSymbolWithAnnotations typeWithAnnotationsOpt,
TypeSymbol typeOpt,
Func<TypeSymbolWithAnnotations, T, bool, bool> typeWithAnnotationsPredicateOpt,
......
......@@ -4248,7 +4248,7 @@ partial class C
);
}
[Fact(Skip = "Hits assertion in CheckValueKind")]
[Fact]
public void SuppressionAsLValue()
{
var source = @"
......@@ -4262,9 +4262,17 @@ void M(string? x)
}
}
";
// https://github.com/dotnet/roslyn/issues/29710 should we produce an error for misuse of suppression on an L-value?
var c = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
c.VerifyDiagnostics();
c.VerifyDiagnostics(
// (6,28): warning CS8600: Converting null literal or possible null value to non-nullable type.
// ref string y = ref x;
Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "x").WithLocation(6, 28),
// (7,29): warning CS8600: Converting null literal or possible null value to non-nullable type.
// ref string y2 = ref x;
Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "x").WithLocation(7, 29),
// (8,10): error CS8598: The suppression operator is not allowed in this context
// (y2! = ref y) = ref y;
Diagnostic(ErrorCode.ERR_IllegalSuppression, "y2").WithLocation(8, 10));
}
[Fact]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册