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 qualified variant selectors with matching? #83

Open
deech opened this issue Mar 27, 2021 · 1 comment
Open

Support qualified variant selectors with matching? #83

deech opened this issue Mar 27, 2021 · 1 comment

Comments

@deech
Copy link

deech commented Mar 27, 2021

The following fails:

import options
import fusion/matching
{.experimental: "caseStmtMacros".}
type
  OKind* = enum O1
  O* = object
    case kind*: OKind
    of O1: o1*: int

case O(kind:O1,o1:1):
  of OKind.O1(o1: @i): echo i

with:

nim c --forceBuild:on --gc:orc -r --verbosity\:0 --hint\[Processing\]\:off --excessiveStackTrace\:on /tmp/matchingtest.nim
/tmp/matchingtest.nim(10, 1) template/generic instantiation of `case` from here
/tmp/matchingtest.nim(11, 11) Error: undeclared field: 'O1' for type matchingtest.O [type declared in /tmp/matchingtest.nim(6, 3)] 
  found 'O1' [enumField declared in /tmp/matchingtest.nim(5, 17)]

nim-compile exited abnormally with code 1 at Sat Mar 27 11:49:16

If I remove the variant qualification it works:

case O(kind:O1,o1:1):
  of O1(o1: @i): echo i

I have variant kinds with name clashes so being able to fully qualify the enum selector would be useful.

@deech deech changed the title Support qualified variant selectors? Support qualified variant selectors with matching? Mar 27, 2021
@haxscramper
Copy link
Contributor

It would be possible to implement, and I think it should be supported. Most likely this is an implementation oversight on my side.

Araq pushed a commit that referenced this issue Jun 3, 2021
…efault>` implementation (#77)

* [TEST]

* [TEST] More tests

* [FIX] #76

* [TEST] String length test

* [DOC] Spec for `opt`

* [DOC] `doc` interaction with `any`

* [DOC] Scale back `opt` features

* [CHECKPOINT] Initial `opt` implementation

* [FEATURE] `opt` implementation

- ADDED ::
  - implement `opt` for field access

* [FIX] Additional check for `nil` values

- CHANGED ::
  Before calling check function on nested match element check using
  `isNil` if entry can is correct. This avoids almost unfixable
  nil-based exceptions triggered deeply within pattern.

* [CLEAN] Internal naming cleanup

- CHANGED ::
  - Use more readable, unabreviated field names (cnt -> foundCount,
    fldElems -> fieldElements)

* [FIX] make style check shut the fuck up

* [FIX] Also bitch with error on typos

* [FIX] oh no, stdlib does not pass style check

 Compiling /home/runner/work/fusion/fusion/fusion/tests/tmatching (from package fusion) using c backend
Error: /home/runner/work/fusion/fusion/nim/lib/std/private/underscored_calls.nim(43, 21) Error: 'nnkArgList' should be: 'nnkArglist'
       Tip: 5 messages have been suppressed, use --verbose to show them.

* [DOC]

* [FIX] Support qualified variant selectors with matching? #83

* [CLEAN] debug prints

* [TEST] Decision matrix predicate test

* [DOC] Predicates and infix operators

* [FIX] Use peg instead of regex for example test

* [FIX] Duplicate assign for matches with conditions

* [CHECKPOINT]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants