Skip to content

Commit 44d5066

Browse files
committed
warnings as error + remove warnings
1 parent 9b063a2 commit 44d5066

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

src/FSharp.MongoDB.Bson/FSharp.MongoDB.Bson.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
78
</PropertyGroup>
89

910
<ItemGroup>

src/FSharp.MongoDB.Bson/Serialization/FSharpTypeHelpers.fs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ module private Helpers =
3434
/// <summary>
3535
/// Returns <c>Some typ</c> when <c>typ</c> is a record type, and <c>None</c> otherwise.
3636
/// </summary>
37-
let (|IsRecord|_|) typ =
38-
let isRecord typ = typ <> null && FSharpType.IsRecord(typ, bindingFlags)
39-
whenType isRecord typ
37+
let (|IsRecord|_|) = function
38+
| Null -> None
39+
| NonNull typ ->
40+
let isRecord typ = FSharpType.IsRecord(typ, bindingFlags)
41+
whenType isRecord typ
4042

4143
/// <summary>
4244
/// Returns <c>Some typ</c> when <c>typ</c> is a top-level union type or when it represents a
4345
/// particular union case, and <c>None</c> otherwise.
4446
/// </summary>
45-
let (|IsUnion|_|) (typ:System.Type) =
46-
let isUnion typ = typ <> null && FSharpType.IsUnion(typ, bindingFlags)
47-
whenType isUnion typ
47+
let (|IsUnion|_|) = function
48+
| Null -> None
49+
| NonNull typ ->
50+
let isUnion typ = FSharpType.IsUnion(typ, bindingFlags)
51+
whenType isUnion typ
4852

4953
/// <summary>
5054
/// Returns true if <c>typ</c> is a generic type with defintion <c>'GenericType</c>.

src/FSharp.MongoDB.Bson/Serialization/FSharpValueSerializer.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ module FSharpValueSerializer =
3838
interface IBsonSerializationProvider with
3939

4040
member __.GetSerializer typ =
41-
let mkSerializer = function
42-
| Some (typ:System.Type) -> System.Activator.CreateInstance typ :?> IBsonSerializer
43-
| None -> null
41+
let mkSerializer typ =
42+
typ
43+
|> Option.map (fun typ -> System.Activator.CreateInstance typ :?> IBsonSerializer)
44+
|> Option.toObj
4445

4546
match typ with
4647
| IsList typ -> Some (mkGenericUsingDef<FSharpListSerializer<_>> typ)

tests/FSharp.MongoDB.Bson.Tests/FSharp.MongoDB.Bson.Tests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
5-
<GenerateProgramFile>false</GenerateProgramFile>
65
<Nullable>enable</Nullable>
6+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
</PropertyGroup>
88

99
<ItemGroup>

tests/FSharp.MongoDB.Bson.Tests/FSharpListSerializationTests.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ module FSharpListSerialization =
8787
let value = { MaybeStrings = [ Some "a"; None; Some "z" ] }
8888

8989
let result = serialize value
90-
let expected = BsonDocument("MaybeStrings", BsonArray [ "a"; null; "z" ])
90+
let expected =
91+
let values: (string|null) array = [| "a"; null; "z" |]
92+
BsonDocument("MaybeStrings", BsonArray values)
9193

9294
result |> should equal expected
9395

9496
[<Test>]
9597
let ``test deserialize a list of optional strings``() =
96-
let doc = BsonDocument("MaybeStrings", BsonArray [ "a"; null; "z" ])
98+
let doc =
99+
let values: (string | null) array = [| "a"; null; "z" |]
100+
BsonDocument("MaybeStrings", BsonArray values)
97101

98102
let result = deserialize doc typeof<Record>
99103
let expected = { MaybeStrings = [ Some "a"; None; Some "z" ] }

tests/FSharp.MongoDB.Bson.Tests/FSharpSetSerializationTests.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ module FSharpSetSerialization =
8787
let value = { MaybeStrings = Set.ofList [ Some "a"; None; Some "z" ] }
8888

8989
let result = serialize value
90-
let expected = BsonDocument("MaybeStrings", BsonArray (Set.ofList ["a"; null; "z"]))
90+
let expected =
91+
let values: (string|null) list = [ "a"; null; "z" ]
92+
BsonDocument("MaybeStrings", BsonArray (Set.ofList values))
9193

9294
result |> should equal expected
9395

9496
[<Test>]
9597
let ``test deserialize a set of optional strings``() =
96-
let doc = BsonDocument("MaybeStrings", BsonArray [ "a"; null; "z" ])
98+
let doc =
99+
let values: (string|null) list = [ "a"; null; "z" ]
100+
BsonDocument("MaybeStrings", BsonArray values)
97101

98102
let result = deserialize doc typeof<Record>
99103
let expected = { MaybeStrings = Set.ofList [ Some "a"; None; Some "z" ] }

0 commit comments

Comments
 (0)