Skip to content

Commit

Permalink
Merge branch 'main' into fix17713
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom authored Sep 16, 2024
2 parents a292814 + b9df594 commit bafaf82
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
* Fix IsUnionCaseTester throwing for non-methods/properties [#17301](https://github.com/dotnet/fsharp/pull/17634)
* Consider `open type` used when the type is an enum and any of the enum cases is used unqualified. ([PR #17628](https://github.com/dotnet/fsharp/pull/17628))
* Guard for possible StackOverflowException when typechecking non recursive modules and namespaces ([PR #17654](https://github.com/dotnet/fsharp/pull/17654))
* Nullable - fix for processing System.Nullable types with nesting ([PR #17736](https://github.com/dotnet/fsharp/pull/17736))
* Fixes for the optimization of simple mappings in array and list comprehensions. ([Issue #17708](https://github.com/dotnet/fsharp/issues/17708), [PR #17711](https://github.com/dotnet/fsharp/pull/17711))


### Added

* Support for nullable reference types ([PR #15181](https://github.com/dotnet/fsharp/pull/15181))
Expand Down
8 changes: 7 additions & 1 deletion src/Compiler/Checking/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,18 @@ For value types, a value is passed even though it is always 0

member this.Advance() = {Data = this.Data; Idx = this.Idx + 1}

let inline isSystemNullable (tspec:ILTypeSpec) =
match tspec.Name,tspec.Enclosing with
| "Nullable`1",["System"] -> true
| "System.Nullable`1",[] -> true
| _ -> false

let inline evaluateFirstOrderNullnessAndAdvance (ilt:ILType) (flags:NullableFlags) =
match ilt with
| ILType.Value tspec when tspec.GenericArgs.IsEmpty -> KnownWithoutNull, flags
// System.Nullable is special-cased in C# spec for nullness metadata.
// You CAN assign 'null' to it, and when boxed, it CAN be boxed to 'null'.
| ILType.Value tspec when tspec.Name = "Nullable`1" && tspec.Enclosing = ["System"] -> KnownWithoutNull, flags
| ILType.Value tspec when isSystemNullable tspec -> KnownWithoutNull, flags
| ILType.Value _ -> KnownWithoutNull, flags.Advance()
| _ -> flags.GetNullness(), flags.Advance()

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ type LanguageVersion(versionText) =
LanguageFeature.LowerSimpleMappingsInComprehensionsToFastLoops, languageVersion90
LanguageFeature.ParsedHashDirectiveArgumentNonQuotes, languageVersion90
LanguageFeature.EmptyBodiedComputationExpressions, languageVersion90
LanguageFeature.EnforceAttributeTargets, languageVersion90

// F# preview
LanguageFeature.EnforceAttributeTargets, previewVersion // waiting for fix of https://github.com/dotnet/fsharp/issues/17731
LanguageFeature.UnmanagedConstraintCsharpInterop, previewVersion // not enabled because: https://github.com/dotnet/fsharp/issues/17509
LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work
LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, previewVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,39 @@ let ``Consumption of nullable C# - no generics, just strings in methods and fiel
Error 3261, Line 25, Col 85, Line 25, Col 97, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."
Error 3261, Line 28, Col 99, Line 28, Col 111, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."
Error 3261, Line 30, Col 97, Line 30, Col 109, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."]


[<FactForNETCOREAPP>]
let ``Regression 17701 - Nullable value type with nested generics`` () =
let csharpLib =
CSharp """
using System;
using System.Collections.Immutable;
#nullable enable
namespace Nullables;
public class NullableClass {
public static ImmutableArray<string?>? nullableImmArrayOfStrings;
public static ImmutableArray<string>? nullableImmArrayOfNotNullStrings;
}""" |> withName "csNullableLib"
|> withCSharpLanguageVersionPreview

FSharp """module FSNullable
open Nullables
let nullablestrNoParams = NullableClass.nullableImmArrayOfStrings
let toOption = NullableClass.nullableImmArrayOfStrings |> Option.ofNullable
let firstString = (toOption.Value |> Seq.head)
let lengthOfIt = firstString.Length
let theOtherOne = NullableClass.nullableImmArrayOfNotNullStrings
"""
|> asLibrary
|> withReferences [csharpLib]
|> withStrictNullness
|> withLangVersionPreview
|> compile
|> shouldFail
|> withDiagnostics
[Error 3261, Line 7, Col 18, Line 7, Col 36, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."]


3 changes: 1 addition & 2 deletions tests/fsharp/typecheck/sigs/neg110.bsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
neg110.fs(5,3,5,15): typecheck error FS1133: No constructors are available for the type 'NotAttribute'

neg110.fs(5,3,5,15): typecheck error FS3242: This type does not inherit Attribute, it will not work correctly with other .NET languages.

0 comments on commit bafaf82

Please sign in to comment.