commit 559e5b7075db70129d91b0767705c83a60ff5690
parent 06407a46e3c9cd660d0bbad7db5de90a85e18fc9
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Sun, 3 Jun 2018 00:33:48 +0200
Temporary hack: allow unsafe-undefined
We should really roll our own optional-arguments mechanism, to prevent that value from causing issues
Diffstat:
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/private/pure-function.rkt b/private/pure-function.rkt
@@ -8,6 +8,7 @@
(only-in typed/racket/unsafe unsafe-require/typed)
(prefix-in te: type-expander)
phc-toolkit
+ version-case
(for-syntax (rename-in racket/base [... …])
racket/match
syntax/modcollapse
@@ -21,6 +22,12 @@
phc-toolkit/untyped
"fully-expanded-grammar-no-set.rkt"))
+(version-case
+ [(version< (version) "6.90.0.29")
+ (begin)]
+ [else
+ (require racket/unsafe/undefined)])
+
(unsafe-require/typed
"pure-unsafe.rkt"
[promise/pure/maybe-stateful? (→ Any Boolean : Promise)]
@@ -221,6 +228,15 @@
;; To allow pure functions which return pure functions, we need to allow
;; check-immutable/c itself
[(eq? x check-immutable/error) #t]
+ ;; racket/unsafe/undefined is used in the expanded code for functions with
+ ;; opetional arguments. We allow it here (for now), even though it is
+ ;; unsafe, because the user (or a library) would need to explicitly require
+ ;; it to cause problems. Otherwise, it will only appear in code generated by
+ ;; typed/racket.
+ [(version-case
+ [(version< (version) "6.90.0.29") #f]
+ [else (eq? x unsafe-undefined)])
+ #t]
;; Otherwise, fail early before mutation causes problems
[else (begin (other) #f)]))
diff --git a/test/test-external-mutation.rkt b/test/test-external-mutation.rkt
@@ -4,7 +4,6 @@
;; This file checks that externally mutating a free variable on which a pure
;; function or promise depends does not affect the function's result.
-
(check-equal? (let ([x 1])
(define d (delay/pure/stateful (add1 x)))
(list (begin (set! x -10) (force d))
@@ -78,4 +77,11 @@
(define-pure/stateful (d #:kw [opt : Number x]) (add1 opt))
(list (begin (set! x -10) (d))
(begin (set! x -11) (d))))
- '(2 2))
-\ No newline at end of file
+ '(2 2))
+
+;; Check that this doesn't cause a run-time error due to the internal use of
+;; unsafe-undefined in the expanded function with optional arguments (starting
+;; from Racket 6.90.0.29)
+(define z 1)
+(define-pure/stateless (d [opt : Number z]) (void))
+(d)
+\ No newline at end of file