From 3c96793c77d5090f46e53d94daf6c8facfce2103 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sat, 10 Jul 2021 01:28:03 +0800 Subject: [PATCH 1/3] Warn unsupported attributes --- src/fsharp/FSComp.txt | 1 + src/fsharp/PostInferenceChecks.fs | 7 ++- src/fsharp/TcGlobals.fs | 2 + src/fsharp/xlf/FSComp.txt.cs.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.de.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.es.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.fr.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.it.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.ja.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.ko.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.pl.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.pt-BR.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.ru.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.tr.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.zh-Hans.xlf | 5 ++ src/fsharp/xlf/FSComp.txt.zh-Hant.xlf | 5 ++ .../ErrorMessages/UnsupportedAttributes.fs | 53 +++++++++++++++++++ .../FSharp.Compiler.ComponentTests.fsproj | 1 + 18 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt index 33b86c208fc..4cc83b0aec1 100644 --- a/src/fsharp/FSComp.txt +++ b/src/fsharp/FSComp.txt @@ -31,6 +31,7 @@ buildUnexpectedTypeArgs,"The non-generic type '%s' does not expect any type argu returnUsedInsteadOfReturnBang,"Consider using 'return!' instead of 'return'." yieldUsedInsteadOfYieldBang,"Consider using 'yield!' instead of 'yield'." tupleRequiredInAbstractMethod,"\nA tuple type is required for one or more arguments. Consider wrapping the given arguments in additional parentheses or review the definition of the interface." +202,unsupportedAttribute,"This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect." 203,buildInvalidWarningNumber,"Invalid warning number '%s'" 204,buildInvalidVersionString,"Invalid version string '%s'" 205,buildInvalidVersionFile,"Invalid version file '%s'" diff --git a/src/fsharp/PostInferenceChecks.fs b/src/fsharp/PostInferenceChecks.fs index d196a60e363..cc8e97ec3dd 100644 --- a/src/fsharp/PostInferenceChecks.fs +++ b/src/fsharp/PostInferenceChecks.fs @@ -1639,7 +1639,12 @@ and CheckDecisionTreeTest cenv env m discrim = | DecisionTreeTest.ActivePatternCase (exp, _, _, _, _, _) -> CheckExprNoByrefs cenv env exp | DecisionTreeTest.Error _ -> () -and CheckAttrib cenv env (Attrib(_, _, args, props, _, _, _)) = +and CheckAttrib cenv env (Attrib(tcref, _, args, props, _, _, m)) = + if [ + cenv.g.attrib_ModuleInitializerAttribute + cenv.g.attrib_CallerArgumentExpressionAttribute + ] |> List.exists (function Some attrib -> tyconRefEq cenv.g attrib.TyconRef tcref | None -> false) then + warning(Error(FSComp.SR.unsupportedAttribute(), m)) props |> List.iter (fun (AttribNamedArg(_, _, _, expr)) -> CheckAttribExpr cenv env expr) args |> List.iter (CheckAttribExpr cenv env) diff --git a/src/fsharp/TcGlobals.fs b/src/fsharp/TcGlobals.fs index 80ef6017a0e..eebcf94fb56 100755 --- a/src/fsharp/TcGlobals.fs +++ b/src/fsharp/TcGlobals.fs @@ -1202,6 +1202,8 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d member val attrib_CallerFilePathAttribute = findSysAttrib "System.Runtime.CompilerServices.CallerFilePathAttribute" member val attrib_CallerMemberNameAttribute = findSysAttrib "System.Runtime.CompilerServices.CallerMemberNameAttribute" member val attrib_SkipLocalsInitAttribute = findSysAttrib "System.Runtime.CompilerServices.SkipLocalsInitAttribute" + member val attrib_ModuleInitializerAttribute = tryFindSysAttrib "System.Runtime.CompilerServices.ModuleInitializerAttribute" + member val attrib_CallerArgumentExpressionAttribute = tryFindSysAttrib "System.Runtime.CompilerServices.CallerArgumentExpressionAttribute" member val attrib_ProjectionParameterAttribute = mk_MFCore_attrib "ProjectionParameterAttribute" member val attrib_CustomOperationAttribute = mk_MFCore_attrib "CustomOperationAttribute" diff --git a/src/fsharp/xlf/FSComp.txt.cs.xlf b/src/fsharp/xlf/FSComp.txt.cs.xlf index f29bb41061c..e377550cd51 100644 --- a/src/fsharp/xlf/FSComp.txt.cs.xlf +++ b/src/fsharp/xlf/FSComp.txt.cs.xlf @@ -607,6 +607,11 @@ Zvažte použití parametru return! namísto return. + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Pro odkazy na rozhraní .NET používejte referenční sestavení, pokud jsou k dispozici (ve výchozím nastavení povolené). diff --git a/src/fsharp/xlf/FSComp.txt.de.xlf b/src/fsharp/xlf/FSComp.txt.de.xlf index 94581794f64..1e4d7679105 100644 --- a/src/fsharp/xlf/FSComp.txt.de.xlf +++ b/src/fsharp/xlf/FSComp.txt.de.xlf @@ -607,6 +607,11 @@ Verwenden Sie ggf. "return!" anstelle von "return". + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Verweisassemblys für .NET Framework-Verweise verwenden, wenn verfügbar (standardmäßig aktiviert). diff --git a/src/fsharp/xlf/FSComp.txt.es.xlf b/src/fsharp/xlf/FSComp.txt.es.xlf index 7883347a3b5..cfcbe891641 100644 --- a/src/fsharp/xlf/FSComp.txt.es.xlf +++ b/src/fsharp/xlf/FSComp.txt.es.xlf @@ -607,6 +607,11 @@ Considere la posibilidad de usar "return!" en lugar de "return". + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Use ensamblados de referencia para las referencias de .NET Framework cuando estén disponibles (habilitado de forma predeterminada). diff --git a/src/fsharp/xlf/FSComp.txt.fr.xlf b/src/fsharp/xlf/FSComp.txt.fr.xlf index 89ce2d2d3ac..f79eff950d1 100644 --- a/src/fsharp/xlf/FSComp.txt.fr.xlf +++ b/src/fsharp/xlf/FSComp.txt.fr.xlf @@ -607,6 +607,11 @@ Utilisez 'return!' à la place de 'return'. + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Utilisez des assemblys de référence pour les références .NET Framework quand ils sont disponibles (activé par défaut). diff --git a/src/fsharp/xlf/FSComp.txt.it.xlf b/src/fsharp/xlf/FSComp.txt.it.xlf index 189164ce3f9..3fba8d38ad4 100644 --- a/src/fsharp/xlf/FSComp.txt.it.xlf +++ b/src/fsharp/xlf/FSComp.txt.it.xlf @@ -607,6 +607,11 @@ Provare a usare 'return!' invece di 'return'. + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Usa gli assembly di riferimento per i riferimenti a .NET Framework quando disponibili (abilitato per impostazione predefinita). diff --git a/src/fsharp/xlf/FSComp.txt.ja.xlf b/src/fsharp/xlf/FSComp.txt.ja.xlf index ded89f6ee73..3aa983608ef 100644 --- a/src/fsharp/xlf/FSComp.txt.ja.xlf +++ b/src/fsharp/xlf/FSComp.txt.ja.xlf @@ -607,6 +607,11 @@ 'return' の代わりに 'return!' を使うことを検討してください。 + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). 使用可能な場合は、.NET Framework リファレンスの参照アセンブリを使用します (既定で有効)。 diff --git a/src/fsharp/xlf/FSComp.txt.ko.xlf b/src/fsharp/xlf/FSComp.txt.ko.xlf index f7b4c5be466..8bd11a5a2d7 100644 --- a/src/fsharp/xlf/FSComp.txt.ko.xlf +++ b/src/fsharp/xlf/FSComp.txt.ko.xlf @@ -607,6 +607,11 @@ 'return'이 아니라 'return!'를 사용하세요. + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). 기본적으로 활성화되는 참조 어셈블리를 .NET Framework 참조에 사용합니다(사용 가능한 경우). diff --git a/src/fsharp/xlf/FSComp.txt.pl.xlf b/src/fsharp/xlf/FSComp.txt.pl.xlf index d0d617eada3..9c3f94da1bf 100644 --- a/src/fsharp/xlf/FSComp.txt.pl.xlf +++ b/src/fsharp/xlf/FSComp.txt.pl.xlf @@ -607,6 +607,11 @@ Rozważ użycie polecenia „return!” zamiast „return”. + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Użyj zestawów odwołań dla odwołań do programu .NET Framework, gdy są dostępne (domyślnie włączone). diff --git a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf index b5d25fdbef5..faeeb5c9ce5 100644 --- a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf +++ b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf @@ -607,6 +607,11 @@ Considere usar 'return!' em vez de 'return'. + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Use assemblies de referência para referências do .NET Framework quando disponível (habilitado por padrão). diff --git a/src/fsharp/xlf/FSComp.txt.ru.xlf b/src/fsharp/xlf/FSComp.txt.ru.xlf index fec0230513f..d49a7aa543e 100644 --- a/src/fsharp/xlf/FSComp.txt.ru.xlf +++ b/src/fsharp/xlf/FSComp.txt.ru.xlf @@ -607,6 +607,11 @@ Рекомендуется использовать "return!" вместо "return". + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Использовать базовые сборки для ссылок на платформу .NET, если базовые сборки доступны (включено по умолчанию). diff --git a/src/fsharp/xlf/FSComp.txt.tr.xlf b/src/fsharp/xlf/FSComp.txt.tr.xlf index fbffea240aa..a87273642e1 100644 --- a/src/fsharp/xlf/FSComp.txt.tr.xlf +++ b/src/fsharp/xlf/FSComp.txt.tr.xlf @@ -607,6 +607,11 @@ 'return' yerine 'return!' kullanmayı deneyin. + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). Kullanılabilir olduğunda, .NET Framework başvuruları için başvuru bütünleştirilmiş kodlarını kullanın (Varsayılan olarak etkindir). diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf index 0ee28c19e69..6533177f43c 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf @@ -607,6 +607,11 @@ 考虑使用 "return!",而非 "return"。 + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). 如果可用,请对 .NET Framework 引用使用引用程序集(默认启用)。 diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf index 17051040efa..6e8f0e7d49f 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf @@ -607,6 +607,11 @@ 請考慮使用 'return!',而不使用 'return'。 + + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect. + + Use reference assemblies for .NET framework references when available (Enabled by default). 請在可行的情況下使用適用於 .NET 架構參考的參考組件 (預設會啟用)。 diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs new file mode 100644 index 00000000000..35069624998 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.ComponentTests.ErrorMessages + +open Xunit +open FSharp.Test.Utilities.Compiler + +module ``Unsupported Attributes`` = + + [] + let ``Warn successfully`` () = + """ +open System.Runtime.CompilerServices +let f (w, [] x : string) = () +let [] g () = () +type C() = + member _.F (w, [] x : string) = () + [] + member _.G() = () + """ + |> FSharp + |> typecheck + |> shouldFail + |> withResults [ + { Error = Warning 202 + Range = { StartLine = 3 + StartColumn = 13 + EndLine = 3 + EndColumn = 37 } + Message = + "This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect." } + { Error = Warning 202 + Range = { StartLine = 4 + StartColumn = 7 + EndLine = 4 + EndColumn = 24 } + Message = + "This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect." } + { Error = Warning 202 + Range = { StartLine = 6 + StartColumn = 22 + EndLine = 6 + EndColumn = 78 } + Message = + "This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect." } + { Error = Warning 202 + Range = { StartLine = 7 + StartColumn = 7 + EndLine = 7 + EndColumn = 56 } + Message = + "This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect." } + ] \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index e4ec28b52a9..f599a3f9b05 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -26,6 +26,7 @@ + From c6646c610df9e2da83e4ed2b68a2c036eafec099 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sun, 11 Jul 2021 02:08:42 +0800 Subject: [PATCH 2/3] Fixes --- src/fsharp/PostInferenceChecks.fs | 5 +---- src/fsharp/TcGlobals.fs | 6 ++++-- .../ErrorMessages/UnsupportedAttributes.fs | 4 +++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fsharp/PostInferenceChecks.fs b/src/fsharp/PostInferenceChecks.fs index cc8e97ec3dd..6008120291e 100644 --- a/src/fsharp/PostInferenceChecks.fs +++ b/src/fsharp/PostInferenceChecks.fs @@ -1640,10 +1640,7 @@ and CheckDecisionTreeTest cenv env m discrim = | DecisionTreeTest.Error _ -> () and CheckAttrib cenv env (Attrib(tcref, _, args, props, _, _, m)) = - if [ - cenv.g.attrib_ModuleInitializerAttribute - cenv.g.attrib_CallerArgumentExpressionAttribute - ] |> List.exists (function Some attrib -> tyconRefEq cenv.g attrib.TyconRef tcref | None -> false) then + if List.exists (tyconRefEq cenv.g tcref) cenv.g.attribs_Unsupported then warning(Error(FSComp.SR.unsupportedAttribute(), m)) props |> List.iter (fun (AttribNamedArg(_, _, _, expr)) -> CheckAttribExpr cenv env expr) args |> List.iter (CheckAttribExpr cenv env) diff --git a/src/fsharp/TcGlobals.fs b/src/fsharp/TcGlobals.fs index eebcf94fb56..87b1810fe34 100755 --- a/src/fsharp/TcGlobals.fs +++ b/src/fsharp/TcGlobals.fs @@ -1202,8 +1202,10 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d member val attrib_CallerFilePathAttribute = findSysAttrib "System.Runtime.CompilerServices.CallerFilePathAttribute" member val attrib_CallerMemberNameAttribute = findSysAttrib "System.Runtime.CompilerServices.CallerMemberNameAttribute" member val attrib_SkipLocalsInitAttribute = findSysAttrib "System.Runtime.CompilerServices.SkipLocalsInitAttribute" - member val attrib_ModuleInitializerAttribute = tryFindSysAttrib "System.Runtime.CompilerServices.ModuleInitializerAttribute" - member val attrib_CallerArgumentExpressionAttribute = tryFindSysAttrib "System.Runtime.CompilerServices.CallerArgumentExpressionAttribute" + member val attribs_Unsupported = [ + tryFindSysAttrib "System.Runtime.CompilerServices.ModuleInitializerAttribute" + tryFindSysAttrib "System.Runtime.CompilerServices.CallerArgumentExpressionAttribute" + ] |> List.choose (Option.map (fun x -> x.TyconRef)) member val attrib_ProjectionParameterAttribute = mk_MFCore_attrib "ProjectionParameterAttribute" member val attrib_CustomOperationAttribute = mk_MFCore_attrib "CustomOperationAttribute" diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs index 35069624998..d2b31048e2e 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs @@ -1,5 +1,6 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. +#if NETCOREAPP namespace FSharp.Compiler.ComponentTests.ErrorMessages open Xunit @@ -50,4 +51,5 @@ type C() = EndColumn = 56 } Message = "This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect." } - ] \ No newline at end of file + ] +#endif \ No newline at end of file From b4c97d5b166d10310caf0dc04417a31f8b9ce180 Mon Sep 17 00:00:00 2001 From: Hadrian Tang Date: Sun, 11 Jul 2021 02:09:45 +0800 Subject: [PATCH 3/3] Fixes again --- .../ErrorMessages/UnsupportedAttributes.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs index d2b31048e2e..ed112bac76c 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnsupportedAttributes.fs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. -#if NETCOREAPP namespace FSharp.Compiler.ComponentTests.ErrorMessages +#if NETCOREAPP open Xunit open FSharp.Test.Utilities.Compiler