From 005b3f720f94bb2cc78b6586de79b045f568494b Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Mon, 16 Mar 2015 13:01:11 -0600 Subject: [PATCH] fix double-expansion in `class` The `class` macro uses `synatx-local-expand-expression`, but it discarded the result and used the original, which implies re-expanding. --- racket/collects/racket/private/class-undef.rkt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/racket/collects/racket/private/class-undef.rkt b/racket/collects/racket/private/class-undef.rkt index f636a33ed8..8980040d55 100644 --- a/racket/collects/racket/private/class-undef.rkt +++ b/racket/collects/racket/private/class-undef.rkt @@ -33,13 +33,17 @@ ;; A wrapper macro that runs the `need-undeed-check?` analysis ;; and adds a boolean argument to a call to `compose-class`: (define-syntax (detect-field-unsafe-undefined stx) - (syntax-case stx () - [(_ compose-class arg ... proc final) - (let-values ([(exp exp-proc) (syntax-local-expand-expression #'proc)]) - (with-syntax ([exp-proc exp-proc] - [need-undef? (need-undefined-check? exp)]) - (syntax/loc stx - (compose-class arg ... proc need-undef? final))))])) + (cond + [(eq? 'expression (syntax-local-context)) + (syntax-case stx () + [(_ compose-class arg ... proc final) + (let-values ([(exp exp-proc) (syntax-local-expand-expression #'proc)]) + (with-syntax ([exp-proc exp-proc] + [need-undef? (need-undefined-check? exp)]) + (syntax/loc stx + (compose-class arg ... exp-proc need-undef? final))))])] + [else + #`(#%expression #,stx)])) ;; Analysis to detect whether any field can be referenced while ;; its value is `unsafe-undefined`, based on `declare-...` annotations