Skip to content

Commit

Permalink
Make duplicate internal definitions an error
Browse files Browse the repository at this point in the history
  • Loading branch information
shirok committed Jan 21, 2023
1 parent c69033e commit 4834f83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2023-01-20 Shiro Kawai <shiro@acm.org>

* src/compile-1.scm (pass1/body-rec): Make duplicate internal
definitions an error.
https://github.com/shirok/Gauche/issues/872

2023-01-19 Shiro Kawai <shiro@acm.org>

* libsrc/data/ring-buffer.scm (ring-buffer-room): API Added.
Expand Down
6 changes: 6 additions & 0 deletions src/compile-1.scm
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@
;; expressions, we re-evaluate <init-expr> and replace the frame entry with
;; (<name> . <lvar>)
(define (pass1/body-rec exprs mframe vframe cenv)
(define (dupe-check var mframe vframe)
(when (or (and (pair? mframe) (assq var mframe))
(and (pair? vframe) (assq var vframe)))
(error "Duplicate internal definition of " var)))
(match exprs
[(((op . args) . src) . rest)
(or (and-let* ([ (or (not vframe) (not (assq op vframe))) ]
Expand Down Expand Up @@ -316,6 +320,7 @@
(error "define without expression is not allowed in R7RS" (caar exprs))
`(,var :rec ,(undefined) . ,src))]
[_ (error "malformed internal define:" (caar exprs))])
(dupe-check (car def) mframe vframe)
(if (not mframe)
(let* ([cenv (cenv-extend cenv '() SYNTAX)]
[mframe (car (cenv-frames cenv))]
Expand All @@ -328,6 +333,7 @@
[(global-identifier=? head define-syntax.) ; internal syntax definition
(match args
[(name trans-spec)
(dupe-check name mframe vframe)
(if (not mframe)
(let* ([cenv (cenv-extend cenv `((,name)) SYNTAX)]
[mframe (car (cenv-frames cenv))]
Expand Down
10 changes: 6 additions & 4 deletions test/number.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2482,14 +2482,14 @@
;;
;; normal quantile function (probit function)
;;
(define (probit p)
(define (probit-ok p)
(define (probit>0 p)
(* (inverse-erf (- (* p 2) 1)) (sqrt 2))) ;; OK
(if (< p 0)
(- 1 (probit>0 (- p)))
(probit>0 p) ))

(define (probit p)
(define (probit-ng p)
(define (probit>0 p)
(* (sqrt 2) (inverse-erf (- (* p 2) 1)))) ;; NG
(if (< p 0)
Expand Down Expand Up @@ -2531,8 +2531,10 @@
;;
;; TEST
;;
(test* "probit(0.025)" -1.959964 (probit 0.025) ~=)
(test* "probit(0.975)" 1.959964 (probit 0.975) ~=)
(test* "probit(0.025) ok pattern" -1.959964 (probit-ok 0.025) ~=)
(test* "probit(0.025) ng pattern" -1.959964 (probit-ng 0.025) ~=)
(test* "probit(0.975) ok pattern" 1.959964 (probit-ok 0.975) ~=)
(test* "probit(0.975) ng pattern" 1.959964 (probit-ng 0.975) ~=)
)

;;------------------------------------------------------------------
Expand Down

0 comments on commit 4834f83

Please sign in to comment.