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

Add constraints for ^Step param type in ranges in (.. ..) operators #17133

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Core/8.0.400.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

* Cache delegate in query extensions. ([PR #17130](https://github.com/dotnet/fsharp/pull/17130))
* Update `AllowNullLiteralAttribute` to also use `AttributeTargets.Interface` ([PR #17173](https://github.com/dotnet/fsharp/pull/17173))
* Missing constraints added for `^Step` parameter in range expressions for `(.. ..)` operator ([PR #17133](https://github.com/dotnet/fsharp/pull/17133))
2 changes: 2 additions & 0 deletions src/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -3758,6 +3758,8 @@ namespace Microsoft.FSharp.Core
and ^Step: (static member Zero: ^Step)
and ^T: equality
and ^T: comparison
and ^Step: equality
and ^Step: comparison
and default ^Step: ^T
and default ^T: int

Expand Down
34 changes: 34 additions & 0 deletions tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,33 @@
if System.UIntPtr.Size >= 8 then
RangeTestsHelpers.unsigned 0x0un 0x1un 0x0un 0xffffffffffffffffun

[<AutoOpen>]
module UserDefinedRange =
type Step(value:int) =
member __.Value = value

static member Zero = Step 0

type Value(value:int) =
member __.Value = value

static member (+)(a:Value, b:Step) = Value(a.Value + b.Value)

interface System.IComparable with
member a.CompareTo(b) =
match b with
| :? Value as b' -> compare a.Value b'.Value
| _ -> failwith "unsupported"

[<Fact>]
let ``Range.UserDefined``() =
// using a user defined type, as opposed to a primitive, as the base type
let rangeList = [Value 0 .. Step 2 .. Value 2]

Check failure on line 1156 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Linux)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1156

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1156,41): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1156 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build MacOS)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1156

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1156,41): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1156 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1156

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1156,41): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface
let rangeArray = [Value 0 .. Step 2 .. Value 2]

Check failure on line 1157 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Linux)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1157

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1157,42): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1157 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build MacOS)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1157

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1157,42): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1157 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1157

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1157,42): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface
Assert.AreEqual(2, rangeList.Length)
Assert.AreEqual(2, rangeArray.Length)


/// These tests' arguments are intentionally _not_ inlined
/// to force the size of the collection (for lists and arrays) or count (for for-loops) to be computed at runtime.
module Runtime =
Expand Down Expand Up @@ -1216,6 +1243,13 @@
let zero, one, min0, max0 = System.UIntPtr 0u, System.UIntPtr 1u, System.UIntPtr System.UInt64.MinValue, System.UIntPtr System.UInt64.MaxValue
RangeTestsHelpers.unsigned zero one min0 max0

[<Fact>]
let ``Range.UserDefined``() =
let rangeList = [Value 0 .. Step 2 .. Value 2]

Check failure on line 1248 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Linux)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1248

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1248,41): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1248 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build MacOS)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1248

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1248,41): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1248 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1248

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1248,41): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface
let rangeArray = [Value 0 .. Step 2 .. Value 2]

Check failure on line 1249 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build Linux)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1249

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1249,42): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1249 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci (Build MacOS)

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1249

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1249,42): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface

Check failure on line 1249 in tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

View check run for this annotation

Azure Pipelines / fsharp-ci

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs#L1249

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs(1249,42): error FS0193: (NETCORE_ENGINEERING_TELEMETRY=Build) The type 'Step' does not support the 'comparison' constraint. For example, it does not support the 'System.IComparable' interface
Assert.AreEqual(2, rangeList.Length)
()

open NonStructuralComparison


Expand Down
Loading