Skip to content

Commit f49e53a

Browse files
T-GroCopilot
andcommitted
Fix CI: replace LINQ extension test case with instance method; format IlxGen.fs
- Replace List<int>.First() (LINQ extension, fails on net472) with List<int>.Contains(1) (instance method, works on all TFMs) - Run fantomas on IlxGen.fs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 68fab52 commit f49e53a

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8676,11 +8676,7 @@ and GenBindingAfterDebugPoint cenv cgbuf eenv bind isStateVar startMarkOpt =
86768676
CommitStartScope cgbuf startMarkOpt
86778677

86788678
// The initialization code for static 'let' and 'do' bindings gets compiled into the initialization .cctor for the whole file
8679-
| _ when
8680-
vspec.IsClassConstructor
8681-
&& isNil vspec.DeclaringEntity.Typars
8682-
&& not isStateVar
8683-
->
8679+
| _ when vspec.IsClassConstructor && isNil vspec.DeclaringEntity.Typars && not isStateVar ->
86848680
let tps, _, _, _, cctorBody, _ =
86858681
IteratedAdjustLambdaToMatchValReprInfo g cenv.amap vspec.ValReprInfo.Value rhsExpr
86868682

tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Language.NullableReferenceTypes
22

33
open Xunit
4+
open FSharp.Test
45
open FSharp.Test.Compiler
56

67
let withNullnessOptions cu =
@@ -2384,8 +2385,8 @@ let main _ = 0
23842385
2, 28, 29, "Trim", "x", "string | null")>]
23852386
[<InlineData("module MyLib\nlet f (x: string | null) = x.Split(',')",
23862387
2, 28, 29, "Split", "x", "string | null")>]
2387-
[<InlineData("module MyLib\nopen System.Linq\nlet f (xs: System.Collections.Generic.List<int> | null) = xs.First()",
2388-
3, 59, 61, "First", "xs", "int seq | null")>]
2388+
[<InlineData("module MyLib\nlet f (xs: System.Collections.Generic.List<int> | null) = xs.Contains(1)",
2389+
2, 59, 61, "Contains", "xs", "System.Collections.Generic.List<int> | null")>]
23892390
[<InlineData("module MyLib\nlet f (xs: System.Collections.Generic.IEnumerable<int> | null) = xs.GetEnumerator()",
23902391
2, 66, 68, "GetEnumerator", "xs", "System.Collections.Generic.IEnumerable<int> | null")>]
23912392
[<InlineData("module MyLib\nopen System.Text\nlet f (sb: StringBuilder | null) = sb.Length <- 0",
@@ -2402,6 +2403,21 @@ let ``Issue 19658 - dot-access on nullable receiver names the binding and member
24022403
$"Nullness warning: Possible dereference of a null value when accessing member '{memberName}' on the nullable value '{bindingName}' of type '{typeName}'."
24032404
]
24042405

2406+
// LINQ extension methods: on net472, BCL lacks NullableAttribute so the
2407+
// extension-method parameter is ambivalent and no FS3261 fires.
2408+
[<FactForNETCOREAPP>]
2409+
let ``Issue 19658 - LINQ extension method dot-access on nullable receiver`` () =
2410+
FSharp """module MyLib
2411+
open System.Linq
2412+
let f (xs: System.Collections.Generic.List<int> | null) = xs.First()"""
2413+
|> asLibrary
2414+
|> typeCheckWithStrictNullness
2415+
|> shouldFail
2416+
|> withDiagnostics [
2417+
Error 3261, Line 3, Col 59, Line 3, Col 61,
2418+
"Nullness warning: Possible dereference of a null value when accessing member 'First' on the nullable value 'xs' of type 'int seq | null'."
2419+
]
2420+
24052421
[<Fact>]
24062422
let ``Issue 19658 - nullness warning on complex receiver omits binding name`` () =
24072423
FSharp """module MyLib

0 commit comments

Comments
 (0)