Skip to content

Commit e818424

Browse files
CopilotT-Gro
andcommitted
Fix null handling and use Set for disabledLanguageFeatures
- 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 <[email protected]>
1 parent cc29923 commit e818424

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/Compiler/Driver/CompilerConfig.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ type TcConfigBuilder =
644644

645645
mutable langVersion: LanguageVersion
646646

647-
mutable disabledLanguageFeatures: LanguageFeature array
647+
mutable disabledLanguageFeatures: Set<LanguageFeature>
648648

649649
mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option
650650

@@ -838,7 +838,7 @@ type TcConfigBuilder =
838838
pathMap = PathMap.empty
839839
applyLineDirectives = true
840840
langVersion = LanguageVersion.Default
841-
disabledLanguageFeatures = [||]
841+
disabledLanguageFeatures = Set.empty
842842
implicitIncludeDir = implicitIncludeDir
843843
defaultFSharpBinariesDir = defaultFSharpBinariesDir
844844
reduceMemoryUsage = reduceMemoryUsage

src/Compiler/Driver/CompilerConfig.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ type TcConfigBuilder =
512512

513513
mutable langVersion: LanguageVersion
514514

515-
mutable disabledLanguageFeatures: LanguageFeature array
515+
mutable disabledLanguageFeatures: Set<LanguageFeature>
516516

517517
mutable xmlDocInfoLoader: IXmlDocumentationInfoLoader option
518518

src/Compiler/Driver/CompilerOptions.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ let languageFlags tcConfigB =
11801180
OptionString(fun switch ->
11811181
let newVersion = setLanguageVersion switch
11821182
// Preserve disabled features when updating version
1183-
tcConfigB.langVersion <- newVersion.WithDisabledFeatures(tcConfigB.disabledLanguageFeatures)),
1183+
tcConfigB.langVersion <- newVersion.WithDisabledFeatures(Set.toArray tcConfigB.disabledLanguageFeatures)),
11841184
None,
11851185
Some(FSComp.SR.optsSetLangVersion ())
11861186
)
@@ -1192,8 +1192,8 @@ let languageFlags tcConfigB =
11921192
OptionStringList(fun featureName ->
11931193
match LanguageVersion.TryParseFeature(featureName) with
11941194
| Some feature ->
1195-
tcConfigB.disabledLanguageFeatures <- Array.append tcConfigB.disabledLanguageFeatures [| feature |]
1196-
tcConfigB.langVersion <- tcConfigB.langVersion.WithDisabledFeatures(tcConfigB.disabledLanguageFeatures)
1195+
tcConfigB.disabledLanguageFeatures <- Set.add feature tcConfigB.disabledLanguageFeatures
1196+
tcConfigB.langVersion <- tcConfigB.langVersion.WithDisabledFeatures(Set.toArray tcConfigB.disabledLanguageFeatures)
11971197
| None -> error (Error(FSComp.SR.optsUnrecognizedLanguageFeature featureName, rangeCmdArgs))),
11981198
None,
11991199
Some(FSComp.SR.optsDisableLanguageFeature ())

src/Compiler/Facilities/LanguageFeatures.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,13 @@ type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array)
440440
||| System.Reflection.BindingFlags.NonPublic
441441
)
442442
|> Array.tryFind (fun case -> System.String.Equals(case.Name, normalized, System.StringComparison.OrdinalIgnoreCase))
443-
|> Option.map (fun case -> Microsoft.FSharp.Reflection.FSharpValue.MakeUnion(case, [||]) :?> LanguageFeature)
443+
|> Option.bind (fun case ->
444+
let union = Microsoft.FSharp.Reflection.FSharpValue.MakeUnion(case, [||])
445+
446+
if isNull union then
447+
None
448+
else
449+
Some(union :?> LanguageFeature))
444450

445451
override x.Equals(yobj: obj) =
446452
match yobj with

0 commit comments

Comments
 (0)