bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#48477: 28.0.50; Seemingly incorrect codegen with multiple string-mat


From: Mattias Engdegård
Subject: bug#48477: 28.0.50; Seemingly incorrect codegen with multiple string-matching pcase patterns
Date: Tue, 18 May 2021 12:44:30 +0200

Serves me right for trying to be clever! Very sorry about that.

Matches would always succeed because the outcome was erroneously transformed 
into a match against a plain pcase variable which never fails. For example, the 
pattern

 (rx (let x "a"))

would expand to
    
 (and (pred stringp)
      (app (lambda (s) (and (string-match (rx (group-n 1 "a")) s)
                            (match-string 1 s)))
           x))

which cannot fail (as long as the input is a string).  Patterns with two or 
more named submatches are not affected because of the structural match used, 
and zero submatches were treated specially anyway.

Please try the attached patch. It encodes non-matches as the number 0 (any 
non-nil non-string value would have done; 0 is cheap to create and test). The 
above pattern now expands to

 (and (pred stringp)
      (app (lambda (s) (if (string-match (rx (group-n 1 "a")) s)
                           (match-string 1 s)
                         0))
           (and x (pred (not numberp)))))

Attachment: 0001-Fix-pcase-rx-patterns-with-a-single-named-submatch-b.patch
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]