From e98f74d0cf576fd5fca0638c695acbde6a72eeb1 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Fri, 8 Oct 2021 14:14:04 -0700 Subject: [PATCH 1/3] Error when ref is used on a parameter or return type of an UnmanagedCallersOnly method Fixes https://github.com/dotnet/roslyn/issues/57025. --- .../Compiler Breaking Changes - DotNet 6.md | 21 +++++++++ .../CSharp/Portable/CSharpResources.resx | 3 ++ .../CSharp/Portable/Errors/ErrorCode.cs | 4 ++ .../SourceMethodSymbolWithAttributes.cs | 11 +++-- .../Portable/xlf/CSharpResources.cs.xlf | 5 +++ .../Portable/xlf/CSharpResources.de.xlf | 5 +++ .../Portable/xlf/CSharpResources.es.xlf | 5 +++ .../Portable/xlf/CSharpResources.fr.xlf | 5 +++ .../Portable/xlf/CSharpResources.it.xlf | 5 +++ .../Portable/xlf/CSharpResources.ja.xlf | 5 +++ .../Portable/xlf/CSharpResources.ko.xlf | 5 +++ .../Portable/xlf/CSharpResources.pl.xlf | 5 +++ .../Portable/xlf/CSharpResources.pt-BR.xlf | 5 +++ .../Portable/xlf/CSharpResources.ru.xlf | 5 +++ .../Portable/xlf/CSharpResources.tr.xlf | 5 +++ .../Portable/xlf/CSharpResources.zh-Hans.xlf | 5 +++ .../Portable/xlf/CSharpResources.zh-Hant.xlf | 5 +++ .../CodeGen/CodeGenFunctionPointersTests.cs | 43 +++++++++++++++++++ 18 files changed, 144 insertions(+), 3 deletions(-) diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md index 950a3b03535f3..3bf241e18706c 100644 --- a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md +++ b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md @@ -121,3 +121,24 @@ These are _function_type_conversions_. class var { } ``` + +5. In Visual Studio 17.1, `ref`/`ref readonly`/`in`/`out` are not allowed to be used on return/parameters of a method attributed with `UnmanagedCallersOnly`. +https://github.com/dotnet/roslyn/issues/57025 + + ```cs + using System.Runtime.InteropServices; + [UnmanagedCallersOnly] + static ref int M1() => throw null; // error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + [UnmanagedCallersOnly] + static ref readonly int M2() => throw null; // error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + [UnmanagedCallersOnly] + static void M3(ref int o) => throw null; // error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + [UnmanagedCallersOnly] + static void M4(in int o) => throw null; // error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + [UnmanagedCallersOnly] + static void M5(out int o) => throw null; // error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + ``` diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 02b7dae1fdb11..a1bc279e72822 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6875,4 +6875,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The operation may overflow at runtime (use 'unchecked' syntax to override) + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 7ce1e0b66cc30..dfc16149ab0b3 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -2001,6 +2001,10 @@ internal enum ErrorCode WRN_MethGrpToNonDel = 8974, ERR_LambdaExplicitReturnTypeVar = 8975, + // Added in VS 17.1. Technically a breaking change, but the code it breaks was already guaranteed to throw + // at runtime. + ERR_CannotUseRefInUnmanagedCallersOnly = 8976, + #endregion // Note: you will need to re-generate compiler code after adding warnings (eng\generate-compiler-code.cmd) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs index f10521a2f2eea..60a068e423039 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs @@ -918,14 +918,19 @@ private void DecodeUnmanagedCallersOnlyAttribute(ref DecodeWellKnownAttributeArg return; } - checkAndReportManagedTypes(ReturnType, returnTypeSyntax, isParam: false, diagnostics); + checkAndReportManagedTypes(ReturnType, this.RefKind, returnTypeSyntax, isParam: false, diagnostics); foreach (var param in Parameters) { - checkAndReportManagedTypes(param.Type, param.GetNonNullSyntaxNode(), isParam: true, diagnostics); + checkAndReportManagedTypes(param.Type, param.RefKind, param.GetNonNullSyntaxNode(), isParam: true, diagnostics); } - static void checkAndReportManagedTypes(TypeSymbol type, SyntaxNode syntax, bool isParam, BindingDiagnosticBag diagnostics) + static void checkAndReportManagedTypes(TypeSymbol type, RefKind refKind, SyntaxNode syntax, bool isParam, BindingDiagnosticBag diagnostics) { + if (refKind != RefKind.None) + { + diagnostics.Add(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, syntax.Location); + } + // use-site diagnostics will be reported at actual parameter declaration site, we're only interested // in reporting managed types being used switch (type.ManagedKindNoUseSiteDiagnostics) diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index d655e4de30de9..a0b11274d6920 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -257,6 +257,11 @@ Rozšiřující metoda, kde jako cíl je nastavený příjemce, se nedá použít jako cíl operátoru &. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. Argumenty InterpolatedStringHandlerArgumentAttribute nemůžou odkazovat na parametr, na kterém se atribut používá. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 907bdcf4abb0b..cbd0ddf02e61e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -257,6 +257,11 @@ Eine Erweiterungsmethode mit einem Empfänger kann nicht als Ziel eines &-Operators verwendet werden. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. InterpolatedStringHandlerArgumentAttribute-Argumente können nicht auf den Parameter verweisen, für den das Attribut verwendet wird. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 457322a31d68e..504c95bad9dfb 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -257,6 +257,11 @@ No se puede usar un método de extensión con un receptor como destino de un operador "&". + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. Los argumentos de InterpolatedStringHandlerArgumentAttribute no pueden hacer referencia al parámetro en el que se usa el atributo. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 5c5cfda908dab..3e7ef39a0e098 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -257,6 +257,11 @@ Impossible d'utiliser une méthode d'extension avec un récepteur en tant que cible d'un opérateur '&'. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. Les arguments de l'attribut InterpolatedStringHandlerArgumentAttribute ne peuvent pas faire référence au paramètre sur lequel l'attribut est utilisé. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 5b11cfcf5a83e..73089bc694442 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -257,6 +257,11 @@ Non è possibile usare un metodo di estensione con un ricevitore come destinazione di un operatore '&'. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. Gli argomenti di InterpolatedStringHandlerArgumentAttribute non possono fare riferimento al parametro in cui viene usato l'attributo. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 0e8d1af5a77b7..1ee5259c2b577 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -257,6 +257,11 @@ レシーバーが '&' 演算子の対象となっている拡張メソッドを使用することはできません。 + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. InterpolatedStringHandlerArgumentAttribute 引数は、属性が使用されているパラメーターを参照できません。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 465defca9b69d..d331271d17d59 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -257,6 +257,11 @@ '&' 연산자의 대상으로 수신기가 있는 확장 메서드는 사용할 수 없습니다. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. InterpolatedStringHandlerArgumentAttribute 인수는 특성이 사용되는 매개 변수를 참조할 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index cd492c7398eff..c7be72f3d3a02 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -257,6 +257,11 @@ Nie można użyć metody rozszerzenia z odbiornikiem jako elementem docelowym operatora „&”. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. Argumenty atrybutu InterpolatedStringHandlerArgumentAttribute nie mogą odwoływać się do parametru, na podstawie którego jest używany atrybut. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index d66021efd6ef7..45a43b312c577 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -257,6 +257,11 @@ Não é possível usar um método de extensão com um receptor como destino de um operador '&'. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. Argumentos InterpolatedStringHandlerArgumentAttribute não podem fazer referência ao parâmetro no qual o atributo é usado. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 43d6cfb383c7e..b56b9ce3d10dc 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -257,6 +257,11 @@ Невозможно использовать метод расширения с приемником в качестве целевого объекта оператора "&". + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. Аргументы InterpolatedStringHandlerArgumentAttribute не могут ссылаться на параметр, в котором используется атрибут. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index ff0b4586bfccf..0d9b3b99dcaa0 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -257,6 +257,11 @@ '&' operatörünün hedefi olarak alıcı içeren bir genişletme metodu kullanılamaz. + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. InterpolatedStringHandlerArgumentAttribute bağımsız değişkenleri özniteliğin kullanıldığı parametreye başvuramaz. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index b52e58c8545ee..8bf0f301a7317 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -257,6 +257,11 @@ 不可将具有接收器的扩展方法用作 "&" 运算符的目标。 + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. InterpolatedStringHandlerArgumentAttribute 参数不能引用在其上使用该属性的参数。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index dcdf032463cff..27422b4a3007f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -257,6 +257,11 @@ 無法使用具有接收器的擴充方法作為 '&' 運算子的目標。 + + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + + InterpolatedStringHandlerArgumentAttribute arguments cannot refer to the parameter the attribute is used on. InterpolatedStringHandlerArgumentAttribute 引數無法參考屬性所使用的參數。 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 7a2df54ab28ea..2c81bed8428d1 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -8111,6 +8111,49 @@ static void M8(T t) where T : unmanaged {} ); } + [Fact, WorkItem(57025, "https://github.com/dotnet/roslyn/issues/57025")] + public void UnmanagedCallersOnlyRequiresNonRef_Errors() + { + var comp = CreateCompilation(new[] { @" +using System.Runtime.InteropServices; +class C +{ + [UnmanagedCallersOnly] + static ref int M1() => throw null; + + [UnmanagedCallersOnly] + static ref readonly int M2() => throw null; + + [UnmanagedCallersOnly] + static void M3(ref int o) => throw null; + + [UnmanagedCallersOnly] + static void M4(in int o) => throw null; + + [UnmanagedCallersOnly] + static void M5(out int o) => throw null; +} +", UnmanagedCallersOnlyAttribute }); + + comp.VerifyDiagnostics( + // (6,12): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // static ref int M1() => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref int").WithLocation(6, 12), + // (9,12): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // static ref readonly int M2() => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref readonly int").WithLocation(9, 12), + // (12,20): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // static void M3(ref int o) => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref int o").WithLocation(12, 20), + // (15,20): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // static void M4(in int o) => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "in int o").WithLocation(15, 20), + // (18,20): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // static void M5(out int o) => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "out int o").WithLocation(18, 20) + ); + } + [Fact] public void UnmanagedCallersOnlyRequiresUnmanagedTypes_Valid() { From ca5802649b300325db1c9e6b7943d8f56c84b2c1 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Fri, 8 Oct 2021 14:47:52 -0700 Subject: [PATCH 2/3] Update additional test baselines --- .../Emit/CodeGen/CodeGenFunctionPointersTests.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 2c81bed8428d1..ab0e04a7647c6 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -9514,7 +9514,13 @@ static class CExt Diagnostic(ErrorCode.ERR_UnmanagedCallersOnlyMethodsCannotBeCalledDirectly, "ls").WithArguments("CExt.Deconstruct(S, out int, out int)").WithLocation(11, 32), // (12,18): error CS8901: 'CExt.Deconstruct(S, out int, out int)' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. // _ = s is (int _, int _); - Diagnostic(ErrorCode.ERR_UnmanagedCallersOnlyMethodsCannotBeCalledDirectly, "(int _, int _)").WithArguments("CExt.Deconstruct(S, out int, out int)").WithLocation(12, 18) + Diagnostic(ErrorCode.ERR_UnmanagedCallersOnlyMethodsCannotBeCalledDirectly, "(int _, int _)").WithArguments("CExt.Deconstruct(S, out int, out int)").WithLocation(12, 18), + // (18,46): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // public static void Deconstruct(this S s, out int i1, out int i2) => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "out int i1").WithLocation(18, 46), + // (18,58): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // public static void Deconstruct(this S s, out int i1, out int i2) => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "out int i2").WithLocation(18, 58) ); } @@ -9617,7 +9623,10 @@ static class CExt comp.VerifyDiagnostics( // (10,29): error CS8901: 'CExt.GetPinnableReference(S)' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. // fixed (int* i = s) - Diagnostic(ErrorCode.ERR_UnmanagedCallersOnlyMethodsCannotBeCalledDirectly, "s").WithArguments("CExt.GetPinnableReference(S)").WithLocation(10, 29) + Diagnostic(ErrorCode.ERR_UnmanagedCallersOnlyMethodsCannotBeCalledDirectly, "s").WithArguments("CExt.GetPinnableReference(S)").WithLocation(10, 29), + // (20,19): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // public static ref int GetPinnableReference(this S s) => throw null; + Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref int").WithLocation(20, 19) ); } From b9902e242e4505034ac44998743e0da97f155939 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Wed, 13 Oct 2021 15:54:28 -0700 Subject: [PATCH 3/3] Wording feedback. --- .../CSharp/Portable/CSharpResources.resx | 2 +- .../CSharp/Portable/xlf/CSharpResources.cs.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.de.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.es.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.fr.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.it.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.ja.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.ko.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.pl.xlf | 4 ++-- .../Portable/xlf/CSharpResources.pt-BR.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.ru.xlf | 4 ++-- .../CSharp/Portable/xlf/CSharpResources.tr.xlf | 4 ++-- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 4 ++-- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 4 ++-- .../Emit/CodeGen/CodeGenFunctionPointersTests.cs | 16 ++++++++-------- 15 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index a1bc279e72822..5bf5fed0d4540 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6876,6 +6876,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The operation may overflow at runtime (use 'unchecked' syntax to override) - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index a0b11274d6920..6f7ae3d780ac9 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index cbd0ddf02e61e..b98ff1d070a80 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 504c95bad9dfb..9d34506a1c840 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 3e7ef39a0e098..e2ce8fc3173c9 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 73089bc694442..2e2333855fb66 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 1ee5259c2b577..5c0fc6944fa62 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index d331271d17d59..befdd10aea2d1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index c7be72f3d3a02..0fa488b3a6b87 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 45a43b312c577..47024e9cfc9e6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index b56b9ce3d10dc..97bc5dfc6c634 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 0d9b3b99dcaa0..1c23dc13126a4 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 8bf0f301a7317..cfe836309121a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 27422b4a3007f..ec80e670acc26 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -258,8 +258,8 @@ - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. - Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. + Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index ab0e04a7647c6..23585616afe86 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -8136,19 +8136,19 @@ class C ", UnmanagedCallersOnlyAttribute }); comp.VerifyDiagnostics( - // (6,12): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (6,12): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // static ref int M1() => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref int").WithLocation(6, 12), - // (9,12): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (9,12): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // static ref readonly int M2() => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref readonly int").WithLocation(9, 12), - // (12,20): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (12,20): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // static void M3(ref int o) => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref int o").WithLocation(12, 20), - // (15,20): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (15,20): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // static void M4(in int o) => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "in int o").WithLocation(15, 20), - // (18,20): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (18,20): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // static void M5(out int o) => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "out int o").WithLocation(18, 20) ); @@ -9515,10 +9515,10 @@ static class CExt // (12,18): error CS8901: 'CExt.Deconstruct(S, out int, out int)' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. // _ = s is (int _, int _); Diagnostic(ErrorCode.ERR_UnmanagedCallersOnlyMethodsCannotBeCalledDirectly, "(int _, int _)").WithArguments("CExt.Deconstruct(S, out int, out int)").WithLocation(12, 18), - // (18,46): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (18,46): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // public static void Deconstruct(this S s, out int i1, out int i2) => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "out int i1").WithLocation(18, 46), - // (18,58): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (18,58): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // public static void Deconstruct(this S s, out int i1, out int i2) => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "out int i2").WithLocation(18, 58) ); @@ -9624,7 +9624,7 @@ static class CExt // (10,29): error CS8901: 'CExt.GetPinnableReference(S)' is attributed with 'UnmanagedCallersOnly' and cannot be called directly. Obtain a function pointer to this method. // fixed (int* i = s) Diagnostic(ErrorCode.ERR_UnmanagedCallersOnlyMethodsCannotBeCalledDirectly, "s").WithArguments("CExt.GetPinnableReference(S)").WithLocation(10, 29), - // (20,19): error CS8976: Cannot use 'ref', 'in', or 'out' in a method attributed with 'UnmanagedCallersOnly'. + // (20,19): error CS8976: Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. // public static ref int GetPinnableReference(this S s) => throw null; Diagnostic(ErrorCode.ERR_CannotUseRefInUnmanagedCallersOnly, "ref int").WithLocation(20, 19) );