-
Notifications
You must be signed in to change notification settings - Fork 846
Add --disableLanguageFeature CLI switch and MSBuild property to selectively disable language features #19167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Added TryParseFeature method to LanguageVersion to parse feature names from strings - Added disabledLanguageFeatures field to TcConfigBuilder to store disabled features - Added SupportsFeature method to TcConfigBuilder that checks both langVersion and disabled features - Added --disableLanguageFeature CLI option in CompilerOptions (repeatable) - Added error message for unrecognized feature names (error 3879) - Created comprehensive tests for the new functionality Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
- Applied fantomas formatting to modified files - Added release notes entry for the new --disableLanguageFeature CLI switch Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
- Modified LanguageVersion to hold disabled features and check them in SupportsFeature - Added SetDisabledFeatures method to LanguageVersion - Updated both langversion and disableLanguageFeature options to call SetDisabledFeatures - This ensures disabled features are respected regardless of option order - Applied code formatting Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
T-Gro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot : Read all comments
As requested, removed the SupportsFeature method from TcConfigBuilder since it's not used anywhere and is redundant - callers can directly use langVersion.SupportsFeature() Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…re parsing - Changed LanguageVersion to use immutable array of disabled features instead of mutable set - Added optional constructor parameter for disabled features array - Added WithDisabledFeatures method that returns a new LanguageVersion instance - Replaced manual feature name mapping with reflection-based TryParseFeature using BindingFlags.NonPublic - Updated CompilerOptions to use immutable pattern with Array.append - Changed disabledLanguageFeatures in TcConfigBuilder from Set to array - Updated tests to use typecheck instead of compile and assert exact error codes - Applied code formatting Addresses feedback from @T-Gro about making the design immutable and using reflection. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
- Added null check in TryParseFeature using Option.bind before downcasting - Changed disabledLanguageFeatures from array to Set in CompilerConfig (better semantics) - Updated CompilerOptions to use Set.add and convert to array when calling WithDisabledFeatures - Applied code formatting Addresses comments from @T-Gro about null handling and using Set in the builder. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Updated compiler_help_output.bsl to include the new --disableLanguageFeature CLI option in help output. Addresses comment from @T-Gro about updating help tests. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
- Added disabledLanguageFeatures field to Fsc task - Added DisabledLanguageFeatures property (takes ITaskItem array) - Updated command line builder to pass each feature with --disableLanguageFeature flag - Follows same pattern as other MSBuild properties This allows .fsproj files to use: <DisabledLanguageFeatures>NameOf;StringInterpolation</DisabledLanguageFeatures> Partial implementation of comment 2627788945 from @T-Gro. Still need to update .targets files. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
🔧 CLI Command Report
✅ Command succeeded, no changes needed. |
…thub.com/dotnet/fsharp into copilot/add-disable-language-feature-cli
tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/disableLanguageFeature.fs
Outdated
Show resolved
Hide resolved
…leLanguageFeature.fs
tests/fsharpqa/Source/CompilerOptions/fsi/help/help40-nologo.437.1033.bsl
Outdated
Show resolved
Hide resolved
tests/fsharpqa/Source/CompilerOptions/fsi/help/help40.437.1033.bsl
Outdated
Show resolved
Hide resolved
- Created docs/release-notes/.Language/10.0.200.md with the new feature entry - Removed duplicate entry from preview.md - Updated PR reference from "TBD" to actual PR #19167 Addresses comment 3768217127. Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Updated in commit 4903ffc:
|
|
I think this may add additional maintenance cost for the tooling with all the possible combinations of language features and versions. @T-Gro Could you please share some context why it was added? Was it because some specific feature was unwanted? |
Summary
This PR adds the
--disableLanguageFeatureCLI switch and corresponding MSBuild property, enabling developers to selectively disable specific F# language features on a per-project basis. This is useful for enforcing coding standards, maintaining compatibility with older codebases, or gradually migrating code that relies on features being phased out.What's Added
CLI Switch
--disableLanguageFeature:<FeatureName>option (repeatable)MSBuild Integration
<DisabledLanguageFeatures>ItemGroup property in .fsproj filesImplementation Details
LanguageFeatureenum cases (no manual mapping required)WithDisabledFeaturescopy-and-update methodSetinTcConfigBuilder, converted to array inLanguageVersionOtherOptionscomparisonUsage Example
CLI:
MSBuild (.fsproj):
Testing
Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.