0.9.13.36: global policy / null-lexenv confusion fix
[sbcl.git] / tests / compiler-2.impure-cload.lisp
1 ;;;; -*- lisp -*-
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
13
14 (cl:in-package :cl-user)
15
16 ;;;; recognize self-calls
17 (declaim (optimize speed))
18
19 ;;;; These three forms should be equivalent.
20
21 ;;;; This used to be a bug in the handling of null-lexenv vs toplevel
22 ;;;; policy: LOCALLY and MACROLET hid the toplevel policy from view.
23
24 (locally
25     (defun foo (n)
26       (frob 'foo)
27       (if (<= n 0)
28           n
29           (foo (1- n)))))
30
31 (progn
32   (defun bar (n)
33     (frob 'bar)
34     (if (<= n 0)
35         n
36         (bar (1- n)))))
37
38 (macrolet ()
39   (defun quux (n)
40     (frob 'quux)
41     (if (<= n 0)
42         n
43         (quux (1- n)))))
44
45 (defun frob (x)
46   (setf (fdefinition x) (constantly 13)))
47
48 (defun test ()
49   (list (foo 1) (bar 1) (quux 1)))
50
51 (assert (equal (test) '(0 0 0)))
52 (assert (equal (test) '(13 13 13))) ; sanity check
53
54 (write-line "//compiler-2.impure.cload.lisp")
55