diff --git a/collects/tests/mzscheme/unsafe.ss b/collects/tests/mzscheme/unsafe.ss index bde2372d42..a7bfccc2f5 100644 --- a/collects/tests/mzscheme/unsafe.ss +++ b/collects/tests/mzscheme/unsafe.ss @@ -311,4 +311,14 @@ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Check that compiling a misapplication of `unsafe-car' and `unsafe-cdr' +;; (which are folding operations in the compiler ) doesn't crash: + +(let ([f (lambda (x) (if x x (unsafe-car 3)))] + [g (lambda (x) (if x x (unsafe-cdr 4)))]) + (test 5 f 5) + (test 5 g 5)) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (report-errs) diff --git a/src/mzscheme/src/list.c b/src/mzscheme/src/list.c index 9f3c85f5ae..869b8b8e8b 100644 --- a/src/mzscheme/src/list.c +++ b/src/mzscheme/src/list.c @@ -3196,11 +3196,13 @@ void scheme_init_ephemerons(void) static Scheme_Object *unsafe_car (int argc, Scheme_Object *argv[]) { + if (scheme_current_thread->constant_folding) return scheme_checked_car(argc, argv); return SCHEME_CAR(argv[0]); } static Scheme_Object *unsafe_cdr (int argc, Scheme_Object *argv[]) { + if (scheme_current_thread->constant_folding) return scheme_checked_cdr(argc, argv); return SCHEME_CDR(argv[0]); }