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
(code:line #:link-target? link-target?-expr)]
[maybe-mode code:blank
(code:line #:mode public)
(code:line #:mode public-final)
(code:line #:mode override)
(code:line #:mode override-final)
(code:line #:mode public-final)
(code:line #:mode augment)
(code:line #:mode augment-final)
(code:line #:mode pubment)
(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
@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
interface.) The @racket[extend] mode is like @racket[override], but
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
([(id arg-spec ...)

View File

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

View File

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