disallow bogus mode arguments and fix related bugs

Fix #131:

- Raise a syntax error when bogus mode arguments are given.
- Fix a bug where `extend-final` and `augment-final` are not recognized
- Document the `public` mode which was already supported but not
  documented.
- Clarify the default mode when `maybe-mode` is not given.
This commit is contained in:
sorawee 2020-06-19 05:29:51 -07:00 committed by GitHub
parent 4b3d3a8296
commit 7f5a2b2648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 15 deletions

View File

@ -1609,14 +1609,15 @@ accepted and propagated to the superclass.}
([maybe-link code:blank ([maybe-link code:blank
(code:line #:link-target? link-target?-expr)] (code:line #:link-target? link-target?-expr)]
[maybe-mode code:blank [maybe-mode code:blank
(code:line #:mode public)
(code:line #:mode public-final)
(code:line #:mode override) (code:line #:mode override)
(code:line #:mode override-final) (code:line #:mode override-final)
(code:line #:mode public-final)
(code:line #:mode augment) (code:line #:mode augment)
(code:line #:mode augment-final) (code:line #:mode augment-final)
(code:line #:mode pubment)
(code:line #:mode extend) (code:line #:mode extend)
(code:line #:mode extend-final)])]{ (code:line #:mode extend-final)
(code:line #:mode pubment)])]{
Like @racket[defproc], but for a method within a @racket[defclass] or Like @racket[defproc], but for a method within a @racket[defclass] or
@racket[definterface] body. @racket[definterface] body.
@ -1626,7 +1627,10 @@ method from a superclass, and so on. (For these purposes, use
@racket[#:mode override] when refining a method of an implemented @racket[#:mode override] when refining a method of an implemented
interface.) The @racket[extend] mode is like @racket[override], but interface.) The @racket[extend] mode is like @racket[override], but
the description of the method should describe only extensions to the the description of the method should describe only extensions to the
superclass implementation.} superclass implementation. When @racket[maybe-mode] is not supplied,
it defaults to @racket[public].
@history[#:changed "1.35" @elem{Added a check against invalid @racket[maybe-mode].}]}
@defform[(defmethod* maybe-mode maybe-link @defform[(defmethod* maybe-mode maybe-link
([(id arg-spec ...) ([(id arg-spec ...)

View File

@ -23,4 +23,4 @@
(define pkg-authors '(mflatt eli)) (define pkg-authors '(mflatt eli))
(define version "1.34") (define version "1.35")

View File

@ -425,26 +425,32 @@
[name1 (car (syntax->list #'(name ...)))]) [name1 (car (syntax->list #'(name ...)))])
(with-syntax ([(extra ...) (with-syntax ([(extra ...)
(let ([finality (let ([finality
(lambda () (lambda (prefix)
(case (syntax-e #'mode) (case (syntax-e #'mode)
[(override-final public-final extend-final) [(override-final public-final extend-final)
#'(" This method is final, so it cannot be overiddden.")] #`(#,prefix "This method is final, so it cannot be overiddden.")]
[(augment-final) [(augment-final)
#'(" This method is final, so it cannot be augmented.")] #`(#,prefix "This method is final, so it cannot be augmented.")]
[else null]))]) [else null]))])
(case (syntax-e #'mode) (case (syntax-e #'mode)
[(pubment) [(pubment)
#'((t "Refine this method with " #'((t "Refine this method with "
(racket augment) "."))] (racket augment) "."))]
[(override override-final extend augment) [(override
#`((t (case (syntax-e #'mode) override-final
[(override override-final) "Overrides "] extend
[(extend extend-final) "Extends "] extend-final
[(augment augment-final) "Augments "]) augment
augment-final)
#`((t #,(case (syntax-e #'mode)
[(override override-final) "Overrides "]
[(extend extend-final) "Extends "]
[(augment augment-final) "Augments "])
(*xmethod/super (quote-syntax/loc cname) 'name1) (*xmethod/super (quote-syntax/loc cname) 'name1)
"." "."
#,@(finality)))] #,@(finality " ")))]
[else null]))]) [(public public-final) #`((t #,@(finality "")))]
[else (raise-syntax-error #f "unrecognized mode" #'mode)]))])
#'(make-meth '(name ...) #'(make-meth '(name ...)
'mode 'mode
(lambda () (lambda ()