Skip to content

Commit 3250b7e

Browse files
authored
Fix ILType.Array import (#16585)
1 parent dfada6a commit 3250b7e

3 files changed

Lines changed: 52 additions & 11 deletions

File tree

src/Compiler/Checking/import.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ let rec ImportILTypeWithNullness (env: ImportMap) m tinst (nf:Nullness.NullableF
316316
| ILType.Void ->
317317
env.g.unit_ty,nf
318318

319-
| ILType.Array(bounds, ty) ->
319+
| ILType.Array(bounds, innerTy) ->
320320
let n = bounds.Rank
321321
let (arrayNullness,nf) = Nullness.evaluateFirstOrderNullnessAndAdvance ty nf
322-
let struct(elemTy,nf) = ImportILTypeWithNullness env m tinst nf ty
322+
let struct(elemTy,nf) = ImportILTypeWithNullness env m tinst nf innerTy
323323
mkArrayTy env.g n arrayNullness elemTy m, nf
324324

325325
| ILType.Boxed tspec | ILType.Value tspec ->

tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ let ``File is not checked twice`` () =
237237
|> Seq.map (fun (k, g) -> k, g |> Seq.map fst |> Seq.toList)
238238
|> Map
239239

240-
Assert.Equal<JobEvent list>([Weakened; Started; Finished], intermediateTypeChecks["FileFirst.fs"])
241-
Assert.Equal<JobEvent list>([Weakened; Started; Finished], intermediateTypeChecks["FileThird.fs"])
240+
Assert.Equal<JobEvent list>([Weakened; Requested; Started; Finished], intermediateTypeChecks["FileFirst.fs"])
241+
Assert.Equal<JobEvent list>([Weakened; Requested; Started; Finished], intermediateTypeChecks["FileThird.fs"])
242242

243243
[<Fact>]
244244
let ``If a file is checked as a dependency it's not re-checked later`` () =
@@ -261,7 +261,7 @@ let ``If a file is checked as a dependency it's not re-checked later`` () =
261261
|> Seq.map (fun (k, g) -> k, g |> Seq.map fst |> Seq.toList)
262262
|> Map
263263

264-
Assert.Equal<JobEvent list>([Weakened; Started; Finished], intermediateTypeChecks["FileThird.fs"])
264+
Assert.Equal<JobEvent list>([Weakened; Requested; Started; Finished; Requested], intermediateTypeChecks["FileThird.fs"])
265265

266266

267267
// [<Fact>] TODO: differentiate complete and minimal checking requests

tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
11
module Language.NullableCSharpImport
22

3-
open FSharp.Test
43
open Xunit
4+
open FSharp.Test
55
open FSharp.Test.Compiler
66

7+
let typeCheckWithStrictNullness cu =
8+
cu
9+
|> withLangVersionPreview
10+
|> withCheckNulls
11+
|> withWarnOn 3261
12+
|> withOptions ["--warnaserror+"]
13+
|> compile
14+
15+
[<Fact>]
16+
let ``Passing null to IlGenerator BeginCatchBlock is fine`` () =
17+
FSharp """module MyLibrary
18+
open System.Reflection.Emit
19+
open System
20+
21+
let passValueToIt (ilg: ILGenerator) =
22+
let maybeType : Type | null = null
23+
ilg.BeginCatchBlock(maybeType)"""
24+
|> asLibrary
25+
|> typeCheckWithStrictNullness
26+
|> shouldSucceed
27+
28+
[<Fact>]
29+
let ``Consumption of netstandard2 BCL api which is not annotated`` () =
30+
FSharp """module MyLibrary
31+
open System.Reflection
32+
33+
[<StructuralEquality; StructuralComparison>]
34+
type PublicKey =
35+
| PublicKey of byte[]
36+
| PublicKeyToken of byte[]
37+
38+
let FromAssemblyName (aname: AssemblyName) =
39+
match aname.GetPublicKey() with
40+
| Null
41+
| NonNull [||] ->
42+
match aname.GetPublicKeyToken() with
43+
| Null
44+
| NonNull [||] -> None
45+
| NonNull bytes -> Some(PublicKeyToken bytes)
46+
| NonNull bytes -> Some(PublicKey bytes)"""
47+
|> asLibrary
48+
|> typeCheckWithStrictNullness
49+
|> shouldSucceed
50+
51+
752
[<FactForNETCOREAPP>]
853
let ``Consumption of nullable C# - no generics, just strings in methods and fields`` () =
954
let csharpLib =
@@ -67,12 +112,8 @@ let ``Consumption of nullable C# - no generics, just strings in methods and fiel
67112
68113
"""
69114
|> asLibrary
70-
|> withLangVersionPreview
71115
|> withReferences [csharpLib]
72-
|> withCheckNulls
73-
|> withWarnOn 3261
74-
|> withOptions ["--warnaserror+"]
75-
|> compile
116+
|> typeCheckWithStrictNullness
76117
|> shouldFail
77118
|> withDiagnostics [
78119
Error 3261, Line 5, Col 40, Line 5, Col 85, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."

0 commit comments

Comments
 (0)