From 1a1bad4e90b07b672f2cc7de47d808790e71d576 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 12 Oct 2020 17:56:35 -0600 Subject: [PATCH] expander: repair literal syntax in test position of `if` Fix mishandling of an expanded `if` where the test position is a syntax object. The expander's compiler pass from expanded objects to linkets knows that the syntax object isn't useful, but it tried to be helpful by preserving the syntax object's content as quoted --- and that content turns out not to be available, so the syntax object was replaced by #f, instead. Closes #3436 --- pkgs/racket-test-core/tests/racket/syntax.rktl | 3 +++ racket/src/bc/src/startup.inc | 2 +- racket/src/cs/schemified/expander.scm | 5 +---- racket/src/expander/compile/expr.rkt | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkgs/racket-test-core/tests/racket/syntax.rktl b/pkgs/racket-test-core/tests/racket/syntax.rktl index 691ee1202d..87761cf25f 100644 --- a/pkgs/racket-test-core/tests/racket/syntax.rktl +++ b/pkgs/racket-test-core/tests/racket/syntax.rktl @@ -82,6 +82,9 @@ (syntax-test #'(+ 3 . 4)) (syntax-test #'(apply + 1 . 2)) +(test 'ok 'check-literal-quote-syntax-as-test (if (quote-syntax yes) 'ok 'bug!)) +(test 'ok2 'check-literal-quote-syntax-as-test (if (quote-syntax #f) 'ok2 'bug!)) + (test 8 (lambda (x) (+ x x)) 4) (define reverse-subtract (lambda (x y) (- y x))) diff --git a/racket/src/bc/src/startup.inc b/racket/src/bc/src/startup.inc index 2f5de76b58..048907fab9 100644 --- a/racket/src/bc/src/startup.inc +++ b/racket/src/bc/src/startup.inc @@ -31623,7 +31623,7 @@ static const char *startup_source = "(compile-quote-syntax" "(parsed-quote-syntax-datum p_0)" " cctx_0)" -"(correlate~ s_0(list 'quote(syntax->datum$1 s_0)))))" +"(correlate~ s_0 ''syntax)))" "(if(parsed-#%variable-reference? p_0)" "(let-values()" "(let-values(((id_0)" diff --git a/racket/src/cs/schemified/expander.scm b/racket/src/cs/schemified/expander.scm index 2a74cea286..1808fb564d 100644 --- a/racket/src/cs/schemified/expander.scm +++ b/racket/src/cs/schemified/expander.scm @@ -38609,10 +38609,7 @@ (compile-quote-syntax (parsed-quote-syntax-datum p3_0) cctx4_0) - (let ((s-exp_0 - (list - 'quote - (syntax->datum$1 s_0)))) + (let ((s-exp_0 ''syntax)) s-exp_0)) (if (|parsed-#%variable-reference?| p3_0) diff --git a/racket/src/expander/compile/expr.rkt b/racket/src/expander/compile/expr.rkt index dfcf462152..8acb28699a 100644 --- a/racket/src/expander/compile/expr.rkt +++ b/racket/src/expander/compile/expr.rkt @@ -106,7 +106,9 @@ [(parsed-quote-syntax? p) (if result-used? (compile-quote-syntax (parsed-quote-syntax-datum p) cctx) - (correlate~ s `(quote ,(syntax->datum s))))] + ;; Note: the datum form of `s` has probably been pruned away, + ;; so don't try to use it here: + (correlate~ s `(quote syntax)))] [(parsed-#%variable-reference? p) (define id (parsed-#%variable-reference-id p)) (correlate~ s