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

Mysterious invalid syntax when building transformer output with quote-syntax #861

Open
dpk opened this issue Aug 7, 2024 · 2 comments
Open

Comments

@dpk
Copy link

dpk commented Aug 7, 2024

(library (quote-syntax-bug)
  (export my-if yes-or-no)
  (import (chezscheme))

  (define-syntax my-if
    (lambda (stx)
      (syntax-case stx ()
        ((_ test then else)
         (list (quote-syntax if) #'test #'then #'else)))))

  (define-syntax yes-or-no
    (lambda (stx)
      (syntax-case stx ()
        ((_ what)
         (my-if (syntax->datum #'what) #''yes #''no))))))
> (import (quote-syntax-bug))
Exception: invalid syntax if at line 9, char 30 of quote-syntax-bug.sls
Type (debug) to enter the debugger.

Changing quote-syntax to syntax in the definition of my-if fixes it. Commenting out yes-or-no and using my-if at the REPL fails. But pasting the definition of my-if into the REPL and invoking it directly from the REPL works.

@mnieper
Copy link
Contributor

mnieper commented Aug 26, 2024

I am investigating this issue. The root cause of the problem seems to be the behaviour of the tests in this program:

(import (chezscheme))
(define qif (quote-syntax if))
(assert (symbol? (syntax->datum qif)))
(assert (identifier? qif))

The first test succeeds, the second test fails.

@mnieper
Copy link
Contributor

mnieper commented Aug 26, 2024

Okay, this was an easy-to-find mistake. The issue is fixed with the following patch:

diff --git a/s/syntax.ss b/s/syntax.ss
index 197d1b10..9e845119 100644
--- a/s/syntax.ss
+++ b/s/syntax.ss
@@ -6027,10 +6027,11 @@
          (_ (syntax-error (source-wrap e w ae))))))

 (global-extend 'core 'quote-syntax
-   (lambda (e r w ae)
+  (lambda (e r w ae)
+    (let ([e (source-wrap e w ae)])
       (syntax-case e ()
-         ((_ e) (build-data no-source (source-wrap (syntax e) w ae)))
-         (_ (syntax-error (source-wrap e w ae))))))
+         ((_ e) (build-data no-source (syntax e)))
+         (_ (syntax-error e))))))

 (global-extend 'core 'syntax
   (let ()

I am going to submit a formal pull request.

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