Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3beb767
Initial plan
Copilot Dec 16, 2025
5ba3745
Add --disableLanguageFeature CLI option with tests
Copilot Dec 16, 2025
7f3bcf8
Apply code formatting and update release notes
Copilot Dec 16, 2025
7dacc20
Fix --disableLanguageFeature to work with LanguageVersion directly
Copilot Dec 16, 2025
2852d9c
Remove unused SupportsFeature method from TcConfigBuilder
Copilot Dec 16, 2025
cc29923
Refactor to use immutable LanguageVersion with reflection-based featu…
Copilot Dec 16, 2025
e818424
Fix null handling and use Set for disabledLanguageFeatures
Copilot Dec 17, 2025
7c0dc12
Update help baseline with --disableLanguageFeature option
Copilot Dec 17, 2025
aa32b6d
Add DisabledLanguageFeatures MSBuild property support
Copilot Dec 17, 2025
2eaf046
Pass DisabledLanguageFeatures property to Fsc task in targets file
Copilot Dec 18, 2025
9da0e1b
Move release notes to correct file (.Language/preview.md)
Copilot Dec 18, 2025
2e3f35c
Fix nullness warning in TryParseFeature by using box before downcast
Copilot Dec 19, 2025
6bc72f2
Merge branch 'main' into copilot/add-disable-language-feature-cli
T-Gro Jan 2, 2026
9599598
Apply patch from /run ilverify
actions-user Jan 2, 2026
f7331e1
Fix KeyNotFoundException by passing bindingFlags to MakeUnion
Copilot Jan 2, 2026
a3008a8
Apply patch from /run fantomas
actions-user Jan 2, 2026
1fb1e78
Fix tests - use nameof with type parameters to test LanguageFeature.N…
Copilot Jan 5, 2026
ecec79a
Update copilot instructions with test execution requirements
Copilot Jan 5, 2026
6d612a1
Investigation findings: Tests reveal --disableLanguageFeature not wor…
Copilot Jan 6, 2026
832ad6b
Fix config clone
T-Gro Jan 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ Always run the core command. Always verify exit codes. No assumptions.
```
Non‑zero → classify & stop.

### CRITICAL TEST EXECUTION RULES
**ALWAYS** run tests before claiming success. **NEVER** mark work complete without verified passing tests.

When running tests, **ALWAYS** report:
- Total number of tests executed
- Number passed / failed / skipped
- Execution duration
- Example: "Ran 5 tests: 5 passed, 0 failed, 0 skipped. Duration: 4.2 seconds"

**ASSUME YOUR CODE IS THE PROBLEM**: When tests fail, ALWAYS assume your implementation is incorrect FIRST. Only after thorough investigation with evidence should you consider other causes like build issues or test infrastructure problems.

**UNDERSTAND WHAT YOU'RE TESTING**: Before writing tests, understand exactly what behavior the feature controls. Research the codebase to see how the feature is actually used, not just how you think it should work.

**TEST INCREMENTALLY**: After each code change, immediately run the relevant tests to verify the change works as expected. Don't accumulate multiple changes before testing.

## 2. Bootstrap (Failure Detection Only)
Two-phase build. No separate bootstrap command.
Early proto/tool errors (e.g. "Error building tools") → `BootstrapFailure` (capture key lines). Stop.
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ type TcConfigBuilder =

mutable langVersion: LanguageVersion

mutable disabledLanguageFeatures: Set<LanguageFeature>

mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option

mutable exiter: Exiter
Expand Down Expand Up @@ -836,6 +838,7 @@ type TcConfigBuilder =
pathMap = PathMap.empty
applyLineDirectives = true
langVersion = LanguageVersion.Default
disabledLanguageFeatures = Set.empty
implicitIncludeDir = implicitIncludeDir
defaultFSharpBinariesDir = defaultFSharpBinariesDir
reduceMemoryUsage = reduceMemoryUsage
Expand Down Expand Up @@ -1421,6 +1424,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.CloneToBuilder() =
{ data with
conditionalDefines = data.conditionalDefines
disabledLanguageFeatures = data.disabledLanguageFeatures
}

member tcConfig.ComputeCanContainEntryPoint(sourceFiles: string list) =
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ type TcConfigBuilder =

mutable langVersion: LanguageVersion

mutable disabledLanguageFeatures: Set<LanguageFeature>

mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option

mutable exiter: Exiter
Expand Down
19 changes: 18 additions & 1 deletion src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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:<string> 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,
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
34 changes: 30 additions & 4 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() =
Expand Down Expand Up @@ -422,6 +430,24 @@ 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()

let bindingFlags =
System.Reflection.BindingFlags.Public
||| System.Reflection.BindingFlags.NonPublic

Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(typeof<LanguageFeature>, bindingFlags)
|> 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, [||], bindingFlags)

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
Expand Down
8 changes: 7 additions & 1 deletion src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[]

Expand All @@ -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
10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading