Skip to content
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

Nullness -> Fix ILType.Array import #16585

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Compiler/Checking/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ let rec ImportILTypeWithNullness (env: ImportMap) m tinst (nf:Nullness.NullableF
| ILType.Void ->
env.g.unit_ty,nf

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

| ILType.Boxed tspec | ILType.Value tspec ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ let ``File is not checked twice`` () =
|> Seq.map (fun (k, g) -> k, g |> Seq.map fst |> Seq.toList)
|> Map

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

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

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


// [<Fact>] TODO: differentiate complete and minimal checking requests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
module Language.NullableCSharpImport

open FSharp.Test
open Xunit
open FSharp.Test
open FSharp.Test.Compiler

let typeCheckWithStrictNullness cu =
cu
|> withLangVersionPreview
|> withCheckNulls
|> withWarnOn 3261
|> withOptions ["--warnaserror+"]
|> compile

[<Fact>]
let ``Passing null to IlGenerator BeginCatchBlock is fine`` () =
FSharp """module MyLibrary
open System.Reflection.Emit
open System

let passValueToIt (ilg: ILGenerator) =
let maybeType : Type | null = null
ilg.BeginCatchBlock(maybeType)"""
|> asLibrary
|> typeCheckWithStrictNullness
|> shouldSucceed

[<Fact>]
let ``Consumption of netstandard2 BCL api which is not annotated`` () =
FSharp """module MyLibrary
open System.Reflection

[<StructuralEquality; StructuralComparison>]
type PublicKey =
| PublicKey of byte[]
| PublicKeyToken of byte[]

let FromAssemblyName (aname: AssemblyName) =
match aname.GetPublicKey() with
| Null
| NonNull [||] ->
match aname.GetPublicKeyToken() with
| Null
| NonNull [||] -> None
| NonNull bytes -> Some(PublicKeyToken bytes)
| NonNull bytes -> Some(PublicKey bytes)"""
|> asLibrary
|> typeCheckWithStrictNullness
|> shouldSucceed


[<FactForNETCOREAPP>]
let ``Consumption of nullable C# - no generics, just strings in methods and fields`` () =
let csharpLib =
Expand Down Expand Up @@ -67,12 +112,8 @@ let ``Consumption of nullable C# - no generics, just strings in methods and fiel

"""
|> asLibrary
|> withLangVersionPreview
|> withReferences [csharpLib]
|> withCheckNulls
|> withWarnOn 3261
|> withOptions ["--warnaserror+"]
|> compile
|> typeCheckWithStrictNullness
|> shouldFail
|> withDiagnostics [
Error 3261, Line 5, Col 40, Line 5, Col 85, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."
Expand Down
Loading