-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersArea-Language DesignFeature - RangeRangeRangeFeature RequestTestTest failures in roslyn-CITest failures in roslyn-CI
Milestone
Description
A Range .. operator is proposed for C# 7.3. This tracks compiler work for that feature.
Proposals:
- https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/ranges.cs
- https://github.com/dotnet/csharplang/blob/master/proposals/csharp-8.0/index-range-changes.md
See also some discussion elsewhere
- Champion "slicing" / Range (16.3, Core 3) csharplang#185
- http://khyperia.com/range.html
- [Proposal] Syntactic ranges #7632
- Discussion: Range operator csharplang#198
- https://github.com/dotnet/csharplang/blob/master/meetings/2017/LDM-2017-07-05.md#slicing
- https://github.com/dotnet/csharplang/blob/master/meetings/2016/LDM-2016-11-01.md#slicing
- Proposal: Slicing #120
- Slicing pattern with range corefxlab#1306
- Generic implementation of Range. corefxlab#1859
- dotnet/corefx#25220
- https://github.com/terrajobst/designs/blob/27a6b1c7df08ae42baa2d5f13bcd9d0e259b47e2/accepted/system-range/system-range.md
Compiler
- Start work on a new feature branch
- New token
.. - Fit into operator precedence somewhere
- Parser for range expressions
- Built-in operator overloading
-
Range operator ..(int, int) -
LongRange operator ..(long, long) - Requires some well-known APIs be present
-
- Permit user-defined operator
- Accepting and binding the syntax
- Decide on some underlying special name
- Overload the user-defined ones when applicable
API questions
- What is the name of the thing?
- Closed interval, half-open interval, or start and count?
- step?
- Implements IEnumerable pattern (using value types)?
- Conversions to array, List, IEnumerable, etc?
- Constructor vs static factory methods
- Is there a conversion (built-in or otherwise) from an int range to a long range?
- Were the types ported to mono? Add types supporting C# 8.0 Ranges mono/mono#12020
namespace System
{
public struct Range
{
public Range(int left, int right) ...
}
public struct LongRange
{
public LongRange(long left, long right) ...
}
}- Supported in
Span<T>andReadonlySpan<T>?
Span<T> x = ...;
Span<T> y = x.Slice([1..0]);IDE
-
The(not applicable to new design)ForEachToForrefactoring should recognize range syntax
Open Issues
- Shall we support dropping one or more operands
1....10..
- Should we have two versions for half-open and closed intervals
- Rust:
..for half-open and and...for closed - Swift:
..<for half-open and...for closed
- Rust:
- Do we want to do something with arrays for
a[1..10]? - Do we want to do something with pattern-matching?
Reactions are currently unavailable
Metadata
Metadata
Labels
Area-CompilersArea-Language DesignFeature - RangeRangeRangeFeature RequestTestTest failures in roslyn-CITest failures in roslyn-CI
Type
Projects
Status
Requires runtime or BCL work