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

Support using Slice to enable slicing syntax expr1[expr2..expr3] #17377

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented Jul 2, 2024

Description

Checklist

  • Test cases added.
  • Release notes entry updated.

Notes

  • It was rather difficult to follow the existing flow of logic in the indexing/slicing typechecking, and it became even harder as I added the new logic, so I refactored it. I hope it's at least a little bit clearer: the main control flow logic is now centralized in the final pattern match.

    match (decodedIndexArgs, setInfo), exprTy with
    // Look for FSharp.Core array and string indexing/slicing helpers.
    | (_, Array) & (ArrayIndexerOrSlicer (path, meth, args), _)
    | (_, String) & (StringIndexerOrSlicer (path, meth, args), _) -> tcArrayOrStringIndexing (path, meth, args)
    // Look for an indexer property, or else assume `Item`.
    | (Indexing, Getting), Indexable indexer
    | (Indexing, Getting), (Array | Nominal) & PossiblyIndexable indexer ->
    propagateThenTcDelayed tpenv expr exprTy (mkDelayedIndexedGet indexer decodedIndexArgs @ delayed)
    // Look for `GetSlice`.
    | (Slicing, Getting), Nominal & GetSliceable slicer ->
    propagateThenTcDelayed tpenv expr exprTy (mkDelayedGetSlice slicer decodedIndexArgs @ delayed)
    // In the absence of `GetSlice`, look for `Slice`.
    | ((Slicing, Getting), Nominal) & Sliceable (tpenv, expr, exprTy) ->
    propagateThenTcDelayed tpenv expr exprTy delayed
    // In the immediate absence of either, assume `GetSlice`.
    | (Slicing, Getting), PossiblyGetSliceable slicer ->
    propagateThenTcDelayed tpenv expr exprTy (mkDelayedGetSlice slicer decodedIndexArgs @ delayed)
    // Look for an indexer property, or else assume `Item`.
    | (Indexing, Setting (setArg, mOfLeftOfSet)), Indexable indexer
    | (Indexing, Setting (setArg, mOfLeftOfSet)), (Array | Nominal) & PossiblyIndexable indexer ->
    propagateThenTcDelayed tpenv expr exprTy (mkDelayedIndexedSet indexer decodedIndexArgs setArg mOfLeftOfSet @ delayed)
    // Assume `SetSlice`.
    | (Slicing, Setting (setArg, mOfLeftOfSet)), (Array | Nominal) ->
    propagateThenTcDelayed tpenv expr exprTy (mkDelayedSetSlice decodedIndexArgs setArg mOfLeftOfSet @ delayed)
    | _ ->
    // deprecated constrained lookup
    error(Error(FSComp.SR.tcObjectOfIndeterminateTypeUsedRequireTypeConstraint(), mWholeExpr))

Copy link
Contributor

github-actions bot commented Jul 2, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

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

Copy link
Contributor

github-actions bot commented Jul 3, 2024

Caution

Repository is on lockdown for maintenance, all merges are on hold.

* The C# spec defines "countable" types as those having either a
  `Length` getter, a `Count` getter, or both; if both, `Length` is
  preferred.

  See: https://github.com/dotnet/csharplang/blob/d9caa3ce753a6b9583da9bdeba316bcb0fe84d44/proposals/csharp-8.0/ranges.md#implicit-index-support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

1 participant