guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
332 stars 22 forks source link

Error: guard1 pattern rebinds a variable #139

Open mathrick opened 2 years ago

mathrick commented 2 years ago

I'm hitting a weird error with the following pattern:

(or ()
    (list :operator operator doc)
    (list doc))

=>
guard1 pattern
 (GUARD1
  (DOC SPECIAL NIL DYNAMIC-EXTENT NIL IGNORABLE NIL BINDER LET
   TYPE T)
  T)
 rebinds a variable (DOC). current context:  (DOC)
   [Condition of type TRIVIA.LEVEL1:GUARD1-PATTERN-NONLINEAR]

Any of the following work just fine:

(or (list :operator operator doc)
    (list doc))

(or ()
    (list :operator operator doc))

;; Work around the bug by using additional OR
(or ()
    (or (list :operator operator doc)
        (list doc)))
guicho271828 commented 2 years ago

Or pattern requires that its subpatterns all share the same set of variables. There was a mechanism that would wrap it up and insert the missing variable, but somehow it doesn't seems to be working.

charJe commented 1 year ago

I believe I also encountered this when trying to match a single &key parameter:

(ematch elem
  ((or (list (or (list keyword name) name)
             default
             suppliedp)
       (list (or (list keyword name) name)
             default)
       (list (list keyword name))
       name)
   ...))