From 91e3a1b5f075cebba361b11bd19bbba37e57e855 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Tue, 2 Jun 2015 17:32:33 -0400 Subject: [PATCH] Make sure that user-specified clauses come before default clauses in `type-case`. Avoids nasty hash ordering bugs. --- typed-racket-lib/typed-racket/rep/rep-utils.rkt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/typed-racket-lib/typed-racket/rep/rep-utils.rkt b/typed-racket-lib/typed-racket/rep/rep-utils.rkt index c842c852..b51b2921 100644 --- a/typed-racket-lib/typed-racket/rep/rep-utils.rkt +++ b/typed-racket-lib/typed-racket/rep/rep-utils.rkt @@ -208,7 +208,7 @@ ;; kws is e.g. '(#:Type #:Filter #:Object #:PathElem) (define-for-syntax (mk-fold hashtable rec-ids kws) (lambda (stx) - (define new-hashtable (hash-copy hashtable)) + (define new-hashtable (make-hasheq)) (define-syntax-class clause (pattern ;; Given name, matcher. @@ -268,8 +268,8 @@ (syntax-parse stx [(tc (~var recs (sized-list kws)) ty clauses:clause ...) ;; map defined types' keywords to their given fold-rhs's. - ;; This is done with a new copy of the hash generated in mk - ;; so we can give special cases for only specific elements. + ;; we will then combine this with the default hash table to generate + ;; the full match expression (for ([k (attribute clauses.kw)] [v (attribute clauses.val)]) (hash-set! new-hashtable k v)) @@ -288,7 +288,9 @@ #`[#,rec-id (make-rename-transformer #'#,rec-id*)])] [(match-clauses ...) ;; create all clauses we fold on, with keyword/body - (hash-map new-hashtable gen-clause)] + (append + (hash-map new-hashtable gen-clause) + (hash-map hashtable gen-clause))] [error-msg (quasisyntax/loc stx (error 'tc "no pattern for ~a" #,fold-target))]) #`(let (let-clauses ... ;; binds #'fold-target to the given element to fold down.