diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index e5c2b65704f..6dfe549ee6f 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -11,6 +11,7 @@ * Allow `let!`, `use!`, `and!` type annotations without requiring parentheses (([PR #18508](https://github.com/dotnet/fsharp/pull/18508) and [PR #18682](https://github.com/dotnet/fsharp/pull/18682))) * Exception names are now validated for illegal characters using the same mechanism as types/modules/namespaces ([Issue #18763](https://github.com/dotnet/fsharp/issues/18763)) * Support tail calls in computation expressions ([PR #18804](https://github.com/dotnet/fsharp/pull/18804)) +* Add `--disableLanguageFeature` CLI switch and MSBuild property to selectively disable specific F# language features on a per-project basis. ([PR #TBD](https://github.com/dotnet/fsharp/pull/TBD)) ### Fixed diff --git a/src/Compiler/Driver/CompilerConfig.fs b/src/Compiler/Driver/CompilerConfig.fs index 5bd5c5266ce..15fe1522fd4 100644 --- a/src/Compiler/Driver/CompilerConfig.fs +++ b/src/Compiler/Driver/CompilerConfig.fs @@ -644,6 +644,8 @@ type TcConfigBuilder = mutable langVersion: LanguageVersion + mutable disabledLanguageFeatures: Set + mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option mutable exiter: Exiter @@ -836,6 +838,7 @@ type TcConfigBuilder = pathMap = PathMap.empty applyLineDirectives = true langVersion = LanguageVersion.Default + disabledLanguageFeatures = Set.empty implicitIncludeDir = implicitIncludeDir defaultFSharpBinariesDir = defaultFSharpBinariesDir reduceMemoryUsage = reduceMemoryUsage diff --git a/src/Compiler/Driver/CompilerConfig.fsi b/src/Compiler/Driver/CompilerConfig.fsi index 646b4477be3..162228bcf96 100644 --- a/src/Compiler/Driver/CompilerConfig.fsi +++ b/src/Compiler/Driver/CompilerConfig.fsi @@ -512,6 +512,8 @@ type TcConfigBuilder = mutable langVersion: LanguageVersion + mutable disabledLanguageFeatures: Set + mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option mutable exiter: Exiter diff --git a/src/Compiler/Driver/CompilerOptions.fs b/src/Compiler/Driver/CompilerOptions.fs index a62dad75eac..ef6c659afa5 100644 --- a/src/Compiler/Driver/CompilerOptions.fs +++ b/src/Compiler/Driver/CompilerOptions.fs @@ -1177,11 +1177,28 @@ let languageFlags tcConfigB = CompilerOption( "langversion", tagLangVersionValues, - OptionString(fun switch -> tcConfigB.langVersion <- setLanguageVersion switch), + OptionString(fun switch -> + let newVersion = setLanguageVersion switch + // Preserve disabled features when updating version + tcConfigB.langVersion <- newVersion.WithDisabledFeatures(Set.toArray tcConfigB.disabledLanguageFeatures)), None, Some(FSComp.SR.optsSetLangVersion ()) ) + // -disableLanguageFeature: Disable a specific language feature by name (repeatable) + CompilerOption( + "disableLanguageFeature", + tagString, + OptionStringList(fun featureName -> + match LanguageVersion.TryParseFeature(featureName) with + | Some feature -> + tcConfigB.disabledLanguageFeatures <- Set.add feature tcConfigB.disabledLanguageFeatures + tcConfigB.langVersion <- tcConfigB.langVersion.WithDisabledFeatures(Set.toArray tcConfigB.disabledLanguageFeatures) + | None -> error (Error(FSComp.SR.optsUnrecognizedLanguageFeature featureName, rangeCmdArgs))), + None, + Some(FSComp.SR.optsDisableLanguageFeature ()) + ) + CompilerOption( "checked", tagNone, diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 512e9b4dca7..4d0b5c2257d 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1570,6 +1570,8 @@ optsCheckNulls,"Enable nullness declarations and checks (%s by default)" fSharpBannerVersion,"%s for F# %s" optsGetLangVersions,"Display the allowed values for language version." optsSetLangVersion,"Specify language version such as 'latest' or 'preview'." +optsDisableLanguageFeature,"Disable a specific language feature by name." +3879,optsUnrecognizedLanguageFeature,"Unrecognized language feature name: '%s'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'." optsSupportedLangVersions,"Supported language versions:" optsStrictIndentation,"Override indentation rules implied by the language version (%s by default)" nativeResourceFormatError,"Stream does not begin with a null resource and is not in '.RES' format." diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index 4b032db713f..d21bf7b27dd 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -107,7 +107,7 @@ type LanguageFeature = | ReturnFromFinal /// LanguageVersion management -type LanguageVersion(versionText) = +type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) = // When we increment language versions here preview is higher than current RTM version static let languageVersion46 = 4.6m @@ -279,11 +279,19 @@ type LanguageVersion(versionText) = let specifiedString = versionToString specified + let disabledFeatures: LanguageFeature array = defaultArg disabledFeaturesArray [||] + /// Check if this feature is supported by the selected langversion member _.SupportsFeature featureId = - match features.TryGetValue featureId with - | true, v -> v <= specified - | false, _ -> false + if Array.contains featureId disabledFeatures then + false + else + match features.TryGetValue featureId with + | true, v -> v <= specified + | false, _ -> false + + /// Create a new LanguageVersion with updated disabled features + member _.WithDisabledFeatures(disabled: LanguageFeature array) = LanguageVersion(versionText, disabled) /// Has preview been explicitly specified member _.IsExplicitlySpecifiedAs50OrBefore() = @@ -422,6 +430,23 @@ type LanguageVersion(versionText) = | true, v -> versionToString v | _ -> invalidArg "feature" "Internal error: Unable to find feature." + /// Try to parse a feature name string to a LanguageFeature option using reflection + static member TryParseFeature(featureName: string) = + let normalized = featureName.Trim() + + Microsoft.FSharp.Reflection.FSharpType.GetUnionCases( + typeof, + System.Reflection.BindingFlags.Public + ||| System.Reflection.BindingFlags.NonPublic + ) + |> Array.tryFind (fun case -> System.String.Equals(case.Name, normalized, System.StringComparison.OrdinalIgnoreCase)) + |> Option.bind (fun case -> + let union = Microsoft.FSharp.Reflection.FSharpValue.MakeUnion(case, [||]) + + match box union with + | null -> None + | obj -> Some(obj :?> LanguageFeature)) + override x.Equals(yobj: obj) = match yobj with | :? LanguageVersion as y -> x.SpecifiedVersion = y.SpecifiedVersion diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 1217b83baf6..74f52b9fbb6 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -101,7 +101,7 @@ type LanguageFeature = type LanguageVersion = /// Create a LanguageVersion management object - new: string -> LanguageVersion + new: string * ?disabledFeaturesArray: LanguageFeature array -> LanguageVersion /// Get the list of valid versions static member ContainsVersion: string -> bool @@ -115,6 +115,9 @@ type LanguageVersion = /// Does the selected LanguageVersion support the specified feature member SupportsFeature: LanguageFeature -> bool + /// Create a new LanguageVersion with updated disabled features + member WithDisabledFeatures: LanguageFeature array -> LanguageVersion + /// Get the list of valid versions static member ValidVersions: string[] @@ -136,4 +139,7 @@ type LanguageVersion = /// Get a version string associated with the given feature. static member GetFeatureVersionString: feature: LanguageFeature -> string + /// Try to parse a feature name string to a LanguageFeature option + static member TryParseFeature: featureName: string -> LanguageFeature option + static member Default: LanguageVersion diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 244be90e142..d2def776c73 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Zobrazí povolené hodnoty pro jazykovou verzi. @@ -1107,6 +1112,11 @@ Neplatná hodnota „{0}“ pro --interfacedata, platná hodnota je: none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Nerozpoznaná hodnota {0} pro parametr --langversion; seznam možností zobrazíte zadáním --langversion:? diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index d1b1782d093..d27bee9d3d0 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Anzeigen der zulässigen Werte für die Sprachversion. @@ -1107,6 +1112,11 @@ Ungültiger Wert „{0}“ für --interfacedata. Gültige Werte sind: none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Unbekannter Wert "{0}" für "--langversion". Verwenden Sie "--langversion:?", um die vollständige Liste anzuzeigen. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index cd311cc7fc5..75e4afde129 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Muestra los valores permitidos para la versión del lenguaje. @@ -1107,6 +1112,11 @@ Valor no válido '{0}' para --interfacedata; los valores válidos son: none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Valor no reconocido "{0}" para --langversion, use --langversion:? para una lista completa diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index e05e9ecdf6c..b2d7d88ec62 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Affichez les valeurs autorisées pour la version du langage. @@ -1107,6 +1112,11 @@ Valeur non valide '{0}' pour --interfacedata. Les valeurs valides sont : none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Valeur non reconnue '{0}' pour --langversion use --langversion:? pour la liste complète diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index a25fd816046..19b3d68cd05 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Visualizzare i valori consentiti per la versione della lingua. @@ -1107,6 +1112,11 @@ Valore non valido '{0}' per --interfacedata. Valori validi sono: none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Valore '{0}' non riconosciuto per --langversion. Per l'elenco completo usare --langversion:? diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 87b7d40df1e..0235f484aba 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. 言語バージョンで許可されている値を表示します。 @@ -1107,6 +1112,11 @@ --interfacedata の値 '{0}' が無効です。有効な値は none、file、compress です。 + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list --langversion の値 '{0}' が認識されません。完全なリストについては、--langversion:? を使用してください diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index f2fe6e20f97..1288727a5a9 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. 언어 버전에 허용되는 값을 표시합니다. @@ -1107,6 +1112,11 @@ --interfacedata에 대한 '{0}' 값이 잘못되었습니다. 올바른 값은 none, file, compress입니다. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list 전체 목록에 대한 --langversion use --langversion:?의 인식할 수 없는 값 '{0}'입니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 23a194ff258..b290decae60 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Wyświetl dozwolone wartości dla wersji językowej. @@ -1107,6 +1112,11 @@ Nieprawidłowa wartość „{0}” dla parametru --interfacedata, prawidłowa wartość to: none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Nierozpoznana wartość „{0}” dla parametru –langversion; podaj parametr –langversion:?, aby uzyskać pełną listę diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 503fc0f073f..09241c13e21 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Exiba os valores permitidos para a versão do idioma. @@ -1107,6 +1112,11 @@ Valor inválido '{0}' para --interfacedata, o valor válido é: none, file, compact. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Valor não reconhecido '{0}' para --langversion use --langversion:? para a lista completa diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 7013fb0bc83..41e913c2084 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Отображение допустимых значений для версии языка. @@ -1107,6 +1112,11 @@ Недопустимое значение "{0}" для --interfacedata. Допустимые значения: none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list Не удалось распознать значение "{0}" для параметра --langversion. Для получения полного списка допустимых значений выполните команду use --langversion:? diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 49d2a295b45..b0d5ecf2c51 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. Dil sürümü için izin verilen değerleri görüntüleyin. @@ -1107,6 +1112,11 @@ --interfacedata için geçersiz '{0}' değeri, geçerli değerler: none, file, compress. + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list --langversion için '{0}' değeri tanınmıyor. Tam liste için --langversion:? kullanın diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 3fc65eebc96..6e1e0dd5f23 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. 显示语言版本的允许值。 @@ -1107,6 +1112,11 @@ --interfacedata 的值 "{0}" 无效,有效值为: none、file、compress。 + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list --langversion 的值“{0}”无法识别,使用 --langversion:? 获取完整列表。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 07fea0efd23..c35f53bbc76 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -1027,6 +1027,11 @@ Compress interface and optimization data files ({0} by default) + + Disable a specific language feature by name. + Disable a specific language feature by name. + + Display the allowed values for language version. 顯示語言版本的允許值。 @@ -1107,6 +1112,11 @@ --interfacedata 的 '{0}' 值無效,有效值為: none、file、compress。 + + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + Unrecognized language feature name: '{0}'. Use a valid feature name such as 'NameOf' or 'StringInterpolation'. + + Unrecognized value '{0}' for --langversion use --langversion:? for complete list 對 --langversion 為無法識別的值 '{0}',對完整清單使用 --langversion:? diff --git a/src/FSharp.Build/Fsc.fs b/src/FSharp.Build/Fsc.fs index 8274812fcb2..62934bfe85f 100644 --- a/src/FSharp.Build/Fsc.fs +++ b/src/FSharp.Build/Fsc.fs @@ -42,6 +42,7 @@ type public Fsc() as this = let mutable highEntropyVA: bool = false let mutable keyFile: string MaybeNull = null let mutable langVersion: string MaybeNull = null + let mutable disabledLanguageFeatures: ITaskItem[] = [||] let mutable noFramework = false let mutable noInterfaceData = false let mutable noOptimizationData = false @@ -152,6 +153,9 @@ type public Fsc() as this = builder.AppendSwitchIfNotNull("--langversion:", langVersion) + for item in disabledLanguageFeatures do + builder.AppendSwitchIfNotNull("--disableLanguageFeature:", item.ItemSpec) + // NoFramework if noFramework then builder.AppendSwitch("--noframework") @@ -463,6 +467,10 @@ type public Fsc() as this = with get () = langVersion and set (s) = langVersion <- s + member _.DisabledLanguageFeatures + with get () = disabledLanguageFeatures + and set (a) = disabledLanguageFeatures <- a + member _.LCID with get () = vslcid and set (p) = vslcid <- p diff --git a/src/FSharp.Build/Microsoft.FSharp.Targets b/src/FSharp.Build/Microsoft.FSharp.Targets index a1385f6aff2..9049f2f7118 100644 --- a/src/FSharp.Build/Microsoft.FSharp.Targets +++ b/src/FSharp.Build/Microsoft.FSharp.Targets @@ -371,6 +371,7 @@ this file. HighEntropyVA="$(HighEntropyVA)" KeyFile="$(KeyOriginatorFile)" LangVersion="$(LangVersion)" + DisabledLanguageFeatures="@(DisabledLanguageFeatures)" LCID="$(LCID)" NoFramework="true" NoInterfaceData="$(NoInterfaceData)" diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/disableLanguageFeature.fs b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/disableLanguageFeature.fs new file mode 100644 index 00000000000..8d91d347b83 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/disableLanguageFeature.fs @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace CompilerOptions.Fsc + +open Xunit +open FSharp.Test +open FSharp.Test.Compiler + +module disableLanguageFeature = + + [] + let ``disableLanguageFeature with valid feature name should typecheck successfully``() = + FSharp """ +printfn "Hello, World" + """ + |> withOptions ["--disableLanguageFeature:NameOf"] + |> typecheck + |> shouldSucceed + |> ignore + + [] + let ``disableLanguageFeature should disable NameOf feature``() = + FSharp """ +let x = 5 +let name = nameof(x) + """ + |> withOptions ["--langversion:latest"; "--disableLanguageFeature:NameOf"] + |> typecheck + |> shouldFail + |> withErrorCode 39 + |> withDiagnosticMessageMatches "The value or constructor 'nameof' is not defined" + |> ignore + + [] + let ``disableLanguageFeature with invalid feature name should fail``() = + FSharp """ +printfn "Hello, World" + """ + |> withOptions ["--disableLanguageFeature:InvalidFeatureName"] + |> typecheck + |> shouldFail + |> withErrorCode 3879 + |> withDiagnosticMessageMatches "Unrecognized language feature name" + |> ignore + + [] + let ``disableLanguageFeature can be used multiple times``() = + FSharp """ +let x = 5 +let name = nameof(x) + """ + |> withOptions ["--langversion:latest"; "--disableLanguageFeature:NameOf"; "--disableLanguageFeature:StringInterpolation"] + |> typecheck + |> shouldFail + |> withErrorCode 39 + |> ignore + + [] + let ``disableLanguageFeature is case insensitive``() = + FSharp """ +let x = 5 +let name = nameof(x) + """ + |> withOptions ["--langversion:latest"; "--disableLanguageFeature:nameof"] + |> typecheck + |> shouldFail + |> withErrorCode 39 + |> ignore diff --git a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/compiler_help_output.bsl b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/compiler_help_output.bsl index beafa217722..92f2b0ac5d4 100644 --- a/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/compiler_help_output.bsl +++ b/tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/misc/compiler_help_output.bsl @@ -80,6 +80,7 @@ Copyright (c) Microsoft Corporation. All Rights Reserved. - LANGUAGE - --langversion:? Display the allowed values for language version. --langversion:{version|latest|preview} Specify language version such as 'latest' or 'preview'. +--disableLanguageFeature: Disable a specific language feature by name. --checked[+|-] Generate overflow checks (off by default) --define: Define conditional compilation symbols (Short form: -d) --mlcompatibility Ignore ML compatibility warnings diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 8f5ace7aade..e7b3f4ddee9 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -299,6 +299,7 @@ +