From cb33d99398b7e8b73799269a93f94f5e7241e658 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 12 Feb 2022 23:02:31 -0800 Subject: [PATCH 1/3] Fix nullable warning on conversion of anonymous function with implicit parameters --- .../Binder/Binder.QueryUnboundLambdaState.cs | 1 + .../Portable/BoundTree/UnboundLambda.cs | 4 +++ .../CSharp/Portable/CSharpResources.resx | 6 ++++ .../CSharp/Portable/Errors/ErrorCode.cs | 1 + .../CSharp/Portable/Errors/ErrorFacts.cs | 2 ++ .../Portable/FlowAnalysis/NullableWalker.cs | 18 +++++++++--- .../Generated/ErrorFacts.Generated.cs | 1 + .../Portable/xlf/CSharpResources.cs.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.de.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.es.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.fr.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.it.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.ja.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.ko.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.pl.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.pt-BR.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.ru.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.tr.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.zh-Hans.xlf | 10 +++++++ .../Portable/xlf/CSharpResources.zh-Hant.xlf | 10 +++++++ .../Semantics/NullableReferenceTypesTests.cs | 28 +++++++++++++++++++ .../Test/Syntax/Diagnostics/DiagnosticTest.cs | 1 + 22 files changed, 188 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs b/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs index a65b7103def98..fc3ad4fe4c1ed 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs @@ -30,6 +30,7 @@ public QueryUnboundLambdaState(Binder binder, RangeVariableMap rangeVariableMap, _bodyFactory = bodyFactory; } + public override bool HasParameterNames() { return true; } public override string ParameterName(int index) { return _parameters[index].Name; } public override bool ParameterIsDiscard(int index) { return false; } public override bool ParameterIsNullChecked(int index) { return false; } diff --git a/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs b/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs index 76baf682e82d8..c982f4771920f 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs @@ -457,6 +457,7 @@ public TypeWithAnnotations InferReturnType(ConversionsBase conversions, NamedTyp public TypeWithAnnotations ParameterTypeWithAnnotations(int index) { return Data.ParameterTypeWithAnnotations(index); } public TypeSymbol ParameterType(int index) { return ParameterTypeWithAnnotations(index).Type; } public Location ParameterLocation(int index) { return Data.ParameterLocation(index); } + public bool HasParameterNames() { return Data.HasParameterNames(); } public string ParameterName(int index) { return Data.ParameterName(index); } public bool ParameterIsDiscard(int index) { return Data.ParameterIsDiscard(index); } public bool ParameterIsNullChecked(int index) { return Data.ParameterIsNullChecked(index); } @@ -517,6 +518,7 @@ internal UnboundLambdaState WithCaching(bool includeCache) public UnboundLambda UnboundLambda => _unboundLambda; public abstract MessageID MessageID { get; } + public abstract bool HasParameterNames(); public abstract string ParameterName(int index); public abstract bool ParameterIsDiscard(int index); public abstract bool ParameterIsNullChecked(int index); @@ -1409,6 +1411,8 @@ public override SyntaxList ParameterAttributes(int index) return _parameterAttributes.IsDefault ? default : _parameterAttributes[index]; } + public override bool HasParameterNames() { return !_parameterNames.IsDefault; } + public override string ParameterName(int index) { Debug.Assert(!_parameterNames.IsDefault && 0 <= index && index < _parameterNames.Length); diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 5fd068b866369..bfb10b6d4bfa3 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -5668,6 +5668,12 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Nullability of reference types in type of parameter doesn't match the target delegate (possibly because of nullability attributes). + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Cannot convert null literal to non-nullable reference type. diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index f891efdf9ae55..949a6aad5a9f9 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1715,6 +1715,7 @@ internal enum ErrorCode ERR_NullableDirectiveTargetExpected = 8668, WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode = 8669, WRN_NullReferenceInitializer = 8670, + WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate = 8671, ERR_MultipleAnalyzerConfigsInSameDir = 8700, diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index 137316a152edc..3d5275977ffc8 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -34,6 +34,7 @@ static ErrorFacts() nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInArgumentForOutput)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate)); + nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullAsNonNullable)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullableValueTypeMayBeNull)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint)); @@ -434,6 +435,7 @@ internal static int GetWarningLevel(ErrorCode code) case ErrorCode.WRN_NullabilityMismatchInArgumentForOutput: case ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate: + case ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate: case ErrorCode.WRN_NullAsNonNullable: case ErrorCode.WRN_NullableValueTypeMayBeNull: case ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint: diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 6ff752fbfba82..c26304468fedc 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -7570,10 +7570,20 @@ void reportBadDelegateReturn(BindingDiagnosticBag bag, MethodSymbol targetInvoke void reportBadDelegateParameter(BindingDiagnosticBag bag, MethodSymbol sourceInvokeMethod, MethodSymbol targetInvokeMethod, ParameterSymbol parameterSymbol, bool topLevel, Location location) { - ReportDiagnostic(ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate, location, - unboundLambda.ParameterName(parameterSymbol.Ordinal), - unboundLambda.MessageID.Localize(), - delegateType); + if (unboundLambda.HasParameterNames()) + { + ReportDiagnostic(ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate, location, + unboundLambda.ParameterName(parameterSymbol.Ordinal), + unboundLambda.MessageID.Localize(), + delegateType); + } + else + { + ReportDiagnostic(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate, location, + parameterSymbol.Ordinal, + unboundLambda.MessageID.Localize(), + delegateType); + } } } diff --git a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs index ea9c801ae3cbb..c07a79bf1a0db 100644 --- a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs @@ -227,6 +227,7 @@ public static bool IsWarning(ErrorCode code) case ErrorCode.WRN_NullabilityMismatchInConstraintsOnPartialImplementation: case ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode: case ErrorCode.WRN_NullReferenceInitializer: + case ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInTypeParameterNotNullConstraint: case ErrorCode.WRN_ParameterConditionallyDisallowsNull: case ErrorCode.WRN_ShouldNotReturn: diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index cf8a63c0ca222..848f54cf8589e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -1637,6 +1637,16 @@ Typ s možnou hodnotou null je zaškrtnut hodnotou null a vyvolá se při hodnotě null. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Parametr {0} musí mít při ukončení hodnotu jinou než null, protože parametr {1} není null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index f26a9dabd49f8..9b49c3c9ec4ee 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -1637,6 +1637,16 @@ Der Nullable-Typ wurde auf NULL-Werte überprüft und wird bei NULL ausgelöst. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Der Parameter "{0}" muss beim Beenden einen Wert ungleich NULL aufweisen, weil Parameter "{1}" nicht NULL ist. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index bf487453d1132..293d6f8c6af3e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -1637,6 +1637,16 @@ El tipo que acepta valores NULL está activado con valor NULL y se iniciará si es null. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. El parámetro "{0}" debe tener un valor que no sea NULL al salir porque el parámetro "{1}" no es NULL. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 42694a4856397..d9292b192c73c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -1637,6 +1637,16 @@ Le type Nullable est activé pour null et lèvera si null. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Le paramètre '{0}' doit avoir une valeur non null au moment de la sortie, car le paramètre '{1}' a une valeur non null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 970507838682e..a31417ed5a4ae 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -1637,6 +1637,16 @@ Il tipo nullable è controllato Null e verrà generato se Null. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Il parametro '{0}' deve avere un valore non Null quando viene terminato perché il parametro '{1}' è non Null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 8e4920c4ec36e..7f309f568bbc0 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -1637,6 +1637,16 @@ Null 許容型は null チェックされており、null の場合はスローされます。 + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. パラメーター '{1}' が null 以外であるため、パラメーター '{0}' には、終了時に null 以外の値が含まれている必要があります。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 02c6a1afa275d..e6ad6092a5079 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -1637,6 +1637,16 @@ nullable 형식은 Null로 확인되며 Null이면 throw됩니다. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. 매개 변수 '{1}'이(가) null이 아니므로 매개 변수 '{0}'은(는) 종료할 때 null이 아닌 값을 가져야 합니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 0b54d90f80b4f..01e4af3ffb5a7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -1637,6 +1637,16 @@ Typ dopuszczający wartość null jest sprawdzony przy użyciu wartości null i będzie widoczny w przypadku wartości null. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Parametr „{0}” musi mieć wartość inną niż null podczas kończenia działania, ponieważ parametr „{1}” ma wartość inną niż null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 5d7a3f8be564c..1502591fa4e80 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -1637,6 +1637,16 @@ O tipo anulável é verificado como nulo e será lançado se for nulo. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. O parâmetro '{0}' precisa ter um valor não nulo durante a saída porque o parâmetro '{1}' não é nulo. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 5e4da7accecbc..fde69c4ea4c7e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -1637,6 +1637,16 @@ Для типа, допускающего значение NULL, выполнена проверка значения NULL. Он будет выдаваться, если ему присвоено значение NULL. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. При выходе параметр "{0}" должен иметь значение, отличное от NULL, так как параметр "{1}" имеет значение, отличное от NULL. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 96705aed73f17..5355823c09353 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -1637,6 +1637,16 @@ Boş değer atanabilir tip null denetimlidir ve null ise atılır. + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. '{1}' parametresi null olmadığından '{0}' parametresi çıkış yaparken null olmayan bir değere sahip olmalıdır. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index d9a0d08a783b2..bce19ee71031f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -1637,6 +1637,16 @@ 对可以为 null 的类型进行了 null 检查,如果为 null,将抛出异常。 + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. 退出时参数“{0}”必须具有非 null 值,因为参数“{1}”是非 null。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 551b2ed6161a4..ded68eb79a4aa 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -1637,6 +1637,16 @@ 可為 Null 的類型會檢查是否為 Null,若為 Null,則會擲回。 + + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). + + + + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). + + Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. 因為參數 '{1}' 不是 null,所以參數 '{0}' 在結束時必須具有非 Null 值。 diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 6456143bb87a9..75fa7c9d730cb 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -155949,5 +155949,33 @@ void M() Diagnostic(ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate, "d2").WithArguments("ref readonly string? D.Invoke()", "D").WithLocation(9, 28) ); } + + [Fact, WorkItem(59336, "https://github.com/dotnet/roslyn/issues/59336")] + public void ParameterNameCrash() + { + var source = @" +#nullable enable + +public delegate void MyDelegate([System.Diagnostics.CodeAnalysis.MaybeNull] object first, [System.Diagnostics.CodeAnalysis.MaybeNull] object second); + +class C +{ + public event MyDelegate? MyEvent; + void M() + { + MyEvent += delegate { }; + MyEvent?.Invoke(new object(), new object()); + } +}"; + var comp = CreateCompilation(new[] { source, MaybeNullAttributeDefinition }); + comp.VerifyDiagnostics( + // (11,20): warning CS8671: Nullability of reference types in type of implicit parameter with index 0 of 'anonymous method' doesn't match the target delegate 'MyDelegate' (possibly because of nullability attributes). + // MyEvent += delegate { }; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate, "delegate { }").WithArguments("0", "anonymous method", "MyDelegate").WithLocation(11, 20), + // (11,20): warning CS8671: Nullability of reference types in type of implicit parameter with index 1 of 'anonymous method' doesn't match the target delegate 'MyDelegate' (possibly because of nullability attributes). + // MyEvent += delegate { }; + Diagnostic(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate, "delegate { }").WithArguments("1", "anonymous method", "MyDelegate").WithLocation(11, 20) + ); + } } } diff --git a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs index ffc6e4ad098c9..e41b24b567a22 100644 --- a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs +++ b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs @@ -311,6 +311,7 @@ public void WarningLevel_2() case ErrorCode.WRN_NullabilityMismatchInArgumentForOutput: case ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate: + case ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate: case ErrorCode.WRN_NullAsNonNullable: case ErrorCode.WRN_NullableValueTypeMayBeNull: case ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint: From a6568c5cab098b0124a85ad27222b0c2453e81d9 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sun, 13 Feb 2022 21:55:17 -0800 Subject: [PATCH 2/3] Simplify --- src/Compilers/CSharp/Portable/CSharpResources.resx | 6 ------ src/Compilers/CSharp/Portable/Errors/ErrorCode.cs | 1 - src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs | 2 -- .../CSharp/Portable/FlowAnalysis/NullableWalker.cs | 8 +------- .../CSharp/Portable/Generated/ErrorFacts.Generated.cs | 1 - .../CSharp/Portable/xlf/CSharpResources.cs.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.de.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.es.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.fr.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.it.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.ja.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.ko.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.pl.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.pt-BR.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.ru.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.tr.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf | 10 ---------- .../CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf | 10 ---------- .../Semantic/Semantics/NullableReferenceTypesTests.cs | 9 +-------- .../CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs | 1 - 20 files changed, 2 insertions(+), 156 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index bfb10b6d4bfa3..5fd068b866369 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -5668,12 +5668,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Nullability of reference types in type of parameter doesn't match the target delegate (possibly because of nullability attributes). - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Cannot convert null literal to non-nullable reference type. diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 949a6aad5a9f9..f891efdf9ae55 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1715,7 +1715,6 @@ internal enum ErrorCode ERR_NullableDirectiveTargetExpected = 8668, WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode = 8669, WRN_NullReferenceInitializer = 8670, - WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate = 8671, ERR_MultipleAnalyzerConfigsInSameDir = 8700, diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index 3d5275977ffc8..137316a152edc 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -34,7 +34,6 @@ static ErrorFacts() nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInArgumentForOutput)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate)); - nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullAsNonNullable)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullableValueTypeMayBeNull)); nullableWarnings.Add(GetId(ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint)); @@ -435,7 +434,6 @@ internal static int GetWarningLevel(ErrorCode code) case ErrorCode.WRN_NullabilityMismatchInArgumentForOutput: case ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate: - case ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate: case ErrorCode.WRN_NullAsNonNullable: case ErrorCode.WRN_NullableValueTypeMayBeNull: case ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint: diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index c26304468fedc..8d66129ef9c28 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -7570,6 +7570,7 @@ void reportBadDelegateReturn(BindingDiagnosticBag bag, MethodSymbol targetInvoke void reportBadDelegateParameter(BindingDiagnosticBag bag, MethodSymbol sourceInvokeMethod, MethodSymbol targetInvokeMethod, ParameterSymbol parameterSymbol, bool topLevel, Location location) { + // For anonymous functions with implicit parameters, no need to report this since the parameters can't be referenced if (unboundLambda.HasParameterNames()) { ReportDiagnostic(ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate, location, @@ -7577,13 +7578,6 @@ void reportBadDelegateParameter(BindingDiagnosticBag bag, MethodSymbol sourceInv unboundLambda.MessageID.Localize(), delegateType); } - else - { - ReportDiagnostic(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate, location, - parameterSymbol.Ordinal, - unboundLambda.MessageID.Localize(), - delegateType); - } } } diff --git a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs index c07a79bf1a0db..ea9c801ae3cbb 100644 --- a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs @@ -227,7 +227,6 @@ public static bool IsWarning(ErrorCode code) case ErrorCode.WRN_NullabilityMismatchInConstraintsOnPartialImplementation: case ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode: case ErrorCode.WRN_NullReferenceInitializer: - case ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInTypeParameterNotNullConstraint: case ErrorCode.WRN_ParameterConditionallyDisallowsNull: case ErrorCode.WRN_ShouldNotReturn: diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 848f54cf8589e..cf8a63c0ca222 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -1637,16 +1637,6 @@ Typ s možnou hodnotou null je zaškrtnut hodnotou null a vyvolá se při hodnotě null. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Parametr {0} musí mít při ukončení hodnotu jinou než null, protože parametr {1} není null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 9b49c3c9ec4ee..f26a9dabd49f8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -1637,16 +1637,6 @@ Der Nullable-Typ wurde auf NULL-Werte überprüft und wird bei NULL ausgelöst. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Der Parameter "{0}" muss beim Beenden einen Wert ungleich NULL aufweisen, weil Parameter "{1}" nicht NULL ist. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 293d6f8c6af3e..bf487453d1132 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -1637,16 +1637,6 @@ El tipo que acepta valores NULL está activado con valor NULL y se iniciará si es null. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. El parámetro "{0}" debe tener un valor que no sea NULL al salir porque el parámetro "{1}" no es NULL. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index d9292b192c73c..42694a4856397 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -1637,16 +1637,6 @@ Le type Nullable est activé pour null et lèvera si null. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Le paramètre '{0}' doit avoir une valeur non null au moment de la sortie, car le paramètre '{1}' a une valeur non null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index a31417ed5a4ae..970507838682e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -1637,16 +1637,6 @@ Il tipo nullable è controllato Null e verrà generato se Null. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Il parametro '{0}' deve avere un valore non Null quando viene terminato perché il parametro '{1}' è non Null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 7f309f568bbc0..8e4920c4ec36e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -1637,16 +1637,6 @@ Null 許容型は null チェックされており、null の場合はスローされます。 - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. パラメーター '{1}' が null 以外であるため、パラメーター '{0}' には、終了時に null 以外の値が含まれている必要があります。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index e6ad6092a5079..02c6a1afa275d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -1637,16 +1637,6 @@ nullable 형식은 Null로 확인되며 Null이면 throw됩니다. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. 매개 변수 '{1}'이(가) null이 아니므로 매개 변수 '{0}'은(는) 종료할 때 null이 아닌 값을 가져야 합니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 01e4af3ffb5a7..0b54d90f80b4f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -1637,16 +1637,6 @@ Typ dopuszczający wartość null jest sprawdzony przy użyciu wartości null i będzie widoczny w przypadku wartości null. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. Parametr „{0}” musi mieć wartość inną niż null podczas kończenia działania, ponieważ parametr „{1}” ma wartość inną niż null. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 1502591fa4e80..5d7a3f8be564c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -1637,16 +1637,6 @@ O tipo anulável é verificado como nulo e será lançado se for nulo. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. O parâmetro '{0}' precisa ter um valor não nulo durante a saída porque o parâmetro '{1}' não é nulo. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index fde69c4ea4c7e..5e4da7accecbc 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -1637,16 +1637,6 @@ Для типа, допускающего значение NULL, выполнена проверка значения NULL. Он будет выдаваться, если ему присвоено значение NULL. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. При выходе параметр "{0}" должен иметь значение, отличное от NULL, так как параметр "{1}" имеет значение, отличное от NULL. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 5355823c09353..96705aed73f17 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -1637,16 +1637,6 @@ Boş değer atanabilir tip null denetimlidir ve null ise atılır. - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. '{1}' parametresi null olmadığından '{0}' parametresi çıkış yaparken null olmayan bir değere sahip olmalıdır. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index bce19ee71031f..d9a0d08a783b2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -1637,16 +1637,6 @@ 对可以为 null 的类型进行了 null 检查,如果为 null,将抛出异常。 - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. 退出时参数“{0}”必须具有非 null 值,因为参数“{1}”是非 null。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index ded68eb79a4aa..551b2ed6161a4 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -1637,16 +1637,6 @@ 可為 Null 的類型會檢查是否為 Null,若為 Null,則會擲回。 - - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter with index {0} of '{1}' doesn't match the target delegate '{2}' (possibly because of nullability attributes). - - - - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - Nullability of reference types in type of implicit parameter doesn't match the target delegate (possibly because of nullability attributes). - - Parameter '{0}' must have a non-null value when exiting because parameter '{1}' is non-null. 因為參數 '{1}' 不是 null,所以參數 '{0}' 在結束時必須具有非 Null 值。 diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 75fa7c9d730cb..7ca7251d2a1e4 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -155968,14 +155968,7 @@ void M() } }"; var comp = CreateCompilation(new[] { source, MaybeNullAttributeDefinition }); - comp.VerifyDiagnostics( - // (11,20): warning CS8671: Nullability of reference types in type of implicit parameter with index 0 of 'anonymous method' doesn't match the target delegate 'MyDelegate' (possibly because of nullability attributes). - // MyEvent += delegate { }; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate, "delegate { }").WithArguments("0", "anonymous method", "MyDelegate").WithLocation(11, 20), - // (11,20): warning CS8671: Nullability of reference types in type of implicit parameter with index 1 of 'anonymous method' doesn't match the target delegate 'MyDelegate' (possibly because of nullability attributes). - // MyEvent += delegate { }; - Diagnostic(ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate, "delegate { }").WithArguments("1", "anonymous method", "MyDelegate").WithLocation(11, 20) - ); + comp.VerifyDiagnostics(); } } } diff --git a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs index e41b24b567a22..ffc6e4ad098c9 100644 --- a/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs +++ b/src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs @@ -311,7 +311,6 @@ public void WarningLevel_2() case ErrorCode.WRN_NullabilityMismatchInArgumentForOutput: case ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate: - case ErrorCode.WRN_NullabilityMismatchInImplicitParameterTypeOfTargetDelegate: case ErrorCode.WRN_NullAsNonNullable: case ErrorCode.WRN_NullableValueTypeMayBeNull: case ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint: From 254412cc7c1df2b44945cc7241dccba21593f68a Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sun, 13 Feb 2022 22:08:25 -0800 Subject: [PATCH 3/3] Remove duplicate property --- .../Portable/Binder/Binder.QueryUnboundLambdaState.cs | 2 -- src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs | 2 +- src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs | 6 ------ .../CSharp/Portable/FlowAnalysis/NullableWalker.cs | 2 +- .../Test/Semantic/Semantics/NullableReferenceTypesTests.cs | 2 +- 5 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs b/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs index fc3ad4fe4c1ed..4f5f4e34a4531 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder.QueryUnboundLambdaState.cs @@ -30,12 +30,10 @@ public QueryUnboundLambdaState(Binder binder, RangeVariableMap rangeVariableMap, _bodyFactory = bodyFactory; } - public override bool HasParameterNames() { return true; } public override string ParameterName(int index) { return _parameters[index].Name; } public override bool ParameterIsDiscard(int index) { return false; } public override bool ParameterIsNullChecked(int index) { return false; } public override SyntaxList ParameterAttributes(int index) => default; - public override bool HasNames { get { return true; } } public override bool HasSignature { get { return true; } } public override bool HasExplicitReturnType(out RefKind refKind, out TypeWithAnnotations returnType) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs index 68b5133be2f19..83e729bc1f0e8 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs @@ -335,7 +335,7 @@ private UnboundLambda BindAnonymousFunction(AnonymousFunctionExpressionSyntax sy // are reported now. ModifierUtils.ToDeclarationModifiers(syntax.Modifiers, diagnostics.DiagnosticBag ?? new DiagnosticBag()); - if (data.HasNames) + if (data.HasSignature) { var binder = new LocalScopeBinder(this); bool allowShadowingNames = binder.Compilation.IsFeatureEnabled(MessageID.IDS_FeatureNameShadowingInNestedFunctions); diff --git a/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs b/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs index c982f4771920f..fce66b2e44abf 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs @@ -457,7 +457,6 @@ public TypeWithAnnotations InferReturnType(ConversionsBase conversions, NamedTyp public TypeWithAnnotations ParameterTypeWithAnnotations(int index) { return Data.ParameterTypeWithAnnotations(index); } public TypeSymbol ParameterType(int index) { return ParameterTypeWithAnnotations(index).Type; } public Location ParameterLocation(int index) { return Data.ParameterLocation(index); } - public bool HasParameterNames() { return Data.HasParameterNames(); } public string ParameterName(int index) { return Data.ParameterName(index); } public bool ParameterIsDiscard(int index) { return Data.ParameterIsDiscard(index); } public bool ParameterIsNullChecked(int index) { return Data.ParameterIsNullChecked(index); } @@ -518,7 +517,6 @@ internal UnboundLambdaState WithCaching(bool includeCache) public UnboundLambda UnboundLambda => _unboundLambda; public abstract MessageID MessageID { get; } - public abstract bool HasParameterNames(); public abstract string ParameterName(int index); public abstract bool ParameterIsDiscard(int index); public abstract bool ParameterIsNullChecked(int index); @@ -528,7 +526,6 @@ internal UnboundLambdaState WithCaching(bool includeCache) public abstract bool HasExplicitlyTypedParameterList { get; } public abstract int ParameterCount { get; } public abstract bool IsAsync { get; } - public abstract bool HasNames { get; } public abstract bool IsStatic { get; } public abstract Location ParameterLocation(int index); public abstract TypeWithAnnotations ParameterTypeWithAnnotations(int index); @@ -1359,7 +1356,6 @@ internal PlainUnboundLambdaState( _isStatic = isStatic; } - public override bool HasNames { get { return !_parameterNames.IsDefault; } } public override bool HasSignature { get { return !_parameterNames.IsDefault; } } @@ -1411,8 +1407,6 @@ public override SyntaxList ParameterAttributes(int index) return _parameterAttributes.IsDefault ? default : _parameterAttributes[index]; } - public override bool HasParameterNames() { return !_parameterNames.IsDefault; } - public override string ParameterName(int index) { Debug.Assert(!_parameterNames.IsDefault && 0 <= index && index < _parameterNames.Length); diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 8d66129ef9c28..d052ecd9e89cf 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -7571,7 +7571,7 @@ void reportBadDelegateReturn(BindingDiagnosticBag bag, MethodSymbol targetInvoke void reportBadDelegateParameter(BindingDiagnosticBag bag, MethodSymbol sourceInvokeMethod, MethodSymbol targetInvokeMethod, ParameterSymbol parameterSymbol, bool topLevel, Location location) { // For anonymous functions with implicit parameters, no need to report this since the parameters can't be referenced - if (unboundLambda.HasParameterNames()) + if (unboundLambda.HasSignature) { ReportDiagnostic(ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate, location, unboundLambda.ParameterName(parameterSymbol.Ordinal), diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 7ca7251d2a1e4..01f4c859d344b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -155951,7 +155951,7 @@ void M() } [Fact, WorkItem(59336, "https://github.com/dotnet/roslyn/issues/59336")] - public void ParameterNameCrash() + public void DelegateConversionWithImplicitParameters() { var source = @" #nullable enable