class: fix name-conflict checking with local names

Closes #1819
This commit is contained in:
Matthew Flatt 2021-04-28 16:20:08 -06:00
parent 3e9a8ccf59
commit 4eed365e1f
2 changed files with 42 additions and 2 deletions

View File

@ -1235,6 +1235,40 @@
(super-new)))])
(test 16 'send-using-local (send (new c%) pub 3)))
;; Make sure local names are checked correctly for deciding
;; conflicting method names:
(let ()
(define-syntax-rule (defclss name% x y)
(begin
(define-local-member-name f)
(define name%
(class object%
(super-new)
(define/public (f) 5)
(define/public (x) 6)
(define/public (y) 7)))
(test 5 'local-f (send (new name%) f))))
(defclss one% f y)
(test 6 'normal-f (send (new one%) f))
(test 7 'normal-y (send (new one%) y))
(define-syntax-rule (defclss2 name% x)
(begin
(define-local-member-name f)
(defclss name% f x)
(test 6 'middle-f (send (new name%) f))))
(defclss2 two% f)
(test 7 'normal-f (send (new two%) f)))
(syntax-test #'(let ()
(define-local-member-name f)
(class object%
(super-new)
(define/public (f) 5)
(define/public (f) 6))))
;; ------------------------------------------------------------
;; `send+' tests

View File

@ -1137,9 +1137,15 @@
(lambda (what l)
(let ([ht (make-hasheq)])
(for-each (lambda (id)
(when (hash-ref ht (syntax-e id) #f)
(define key (let ([l-id (lookup-localize id)])
(if (identifier? l-id)
(syntax-e l-id)
;; For a given localized id, `lookup-localize`
;; will return the same (eq?) value
l-id)))
(when (hash-ref ht key #f)
(bad (format "duplicate declared external ~a name" what) id))
(hash-set! ht (syntax-e id) #t))
(hash-set! ht key #t))
l)))])
;; method names
(check-dup "method" (map cdr (append publics overrides augrides