dotnet / fsharp

The F# compiler, F# core library, F# language service, and F# tooling integration for Visual Studio
https://dotnet.microsoft.com/languages/fsharp
MIT License
3.88k stars 783 forks source link

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

Open abelbraaksma opened 4 months ago

abelbraaksma commented 4 months ago

Description

Using user-defined types with ranges (that is, the .. .. operator as in for x in y .. step .. z do and the like) are required to have comparison and equality constraints. While the definition of (.. ..) has these constraints on the counter type, and it has and default ^Step : ^T, the compiler does not infer from this that this requires the ^Step parameter to have the same constraints.

This should be caught by the compiler as a discrepancy between the *.fsi file and the implementation file.

Without using the constraints on your type, code would compile, but always fail at runtime. See linked issue for details.

Fixes #6238

Checklist

github-actions[bot] commented 4 months ago

:heavy_exclamation_mark: Release notes required


:white_check_mark: Found changes and release notes in following paths:

Change path Release notes path Description
src/FSharp.Core docs/release-notes/.FSharp.Core/8.0.400.md