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

Conversation

abelbraaksma
Copy link
Contributor

@abelbraaksma abelbraaksma commented May 10, 2024

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

  • Test cases added (note: there seem to be ZERO cases for user defined types)
    • TODO: a few more test cases and ideally a compile-time test case
    • TODO: fix new test case that's now (deliberately) failing
  • Release notes entry updated

Copy link
Contributor

github-actions bot commented May 10, 2024

❗ Release notes required


✅ 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

@abelbraaksma abelbraaksma force-pushed the ranges-with-step-constraints branch from 539ba22 to 05f1282 Compare May 10, 2024 11:20
@abelbraaksma abelbraaksma added Area-Library Issues for FSharp.Core not covered elsewhere Area-Compiler-SRTP bugs in SRTP inference, resolution, witness passing, code gen labels May 10, 2024
@abelbraaksma abelbraaksma force-pushed the ranges-with-step-constraints branch from 37f207d to 93223e4 Compare May 10, 2024 11:32
@abelbraaksma abelbraaksma force-pushed the ranges-with-step-constraints branch from 93223e4 to 9775798 Compare May 23, 2024 21:32
@abelbraaksma abelbraaksma force-pushed the ranges-with-step-constraints branch from 9775798 to 3ef8255 Compare May 23, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-SRTP bugs in SRTP inference, resolution, witness passing, code gen Area-Library Issues for FSharp.Core not covered elsewhere
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

Operators.( .. .. ) throws an ArgumentException when ^Step does not implement IComparable
1 participant