forked from alex-eg/sex
tell a spec default by its body, not its length
A required method with a docstring or a comment counted as a default: the realization could leave it out, and got a prototype with no definition or a function with no return.
This commit is contained in:
14
semen.scm
14
semen.scm
@@ -346,11 +346,21 @@
|
|||||||
(append (map (lambda (g) (cons g #t)) given)
|
(append (map (lambda (g) (cons g #t)) given)
|
||||||
(filter-map
|
(filter-map
|
||||||
(lambda (w)
|
(lambda (w)
|
||||||
(and (> (length w) 4) ; carries a body, so a default
|
(and (spec-default? w)
|
||||||
(not (find (lambda (g) (eq? (second g) (second w))) given))
|
(not (find (lambda (g) (eq? (second g) (second w))) given))
|
||||||
(cons (substitute-parameter parameter type w) #f)))
|
(cons (substitute-parameter parameter type w) #f)))
|
||||||
wanted)))
|
wanted)))
|
||||||
|
|
||||||
|
;;; A docstring or a comment is not a body, so
|
||||||
|
;;;
|
||||||
|
;;; (fn s ((self (* const T))) void "what s is for")
|
||||||
|
;;;
|
||||||
|
;;; is still a method every realization has to write.
|
||||||
|
(define (spec-default? method)
|
||||||
|
(let-values (((doc fn) (extract-fn-docstring (strip-fn-header-comments method))))
|
||||||
|
(any (lambda (form) (not (comment-form? form)))
|
||||||
|
(drop fn (fn-header-length fn)))))
|
||||||
|
|
||||||
(define (check-realization form name type parameter wanted given)
|
(define (check-realization form name type parameter wanted given)
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (g)
|
(lambda (g)
|
||||||
@@ -369,7 +379,7 @@
|
|||||||
given)
|
given)
|
||||||
(let ((missing (filter-map
|
(let ((missing (filter-map
|
||||||
(lambda (w)
|
(lambda (w)
|
||||||
(and (= (length w) 4) ; no body, so required
|
(and (not (spec-default? w))
|
||||||
(not (find (lambda (g) (eq? (second g) (second w))) given))
|
(not (find (lambda (g) (eq? (second g) (second w))) given))
|
||||||
(second w)))
|
(second w)))
|
||||||
wanted)))
|
wanted)))
|
||||||
|
|||||||
@@ -198,6 +198,23 @@
|
|||||||
" (fn q ((a (* const T))) void))"
|
" (fn q ((a (* const T))) void))"
|
||||||
"(realize (p v) (fn s ((a (* const v))) void (return)))")
|
"(realize (p v) (fn s ((a (* const v))) void (return)))")
|
||||||
"q"))
|
"q"))
|
||||||
|
(test-assert "a docstring is not a body"
|
||||||
|
(reports? (string-append "(record v ((x int)))"
|
||||||
|
"(spec (p T) (fn s ((a (* const T))) void \"doc\"))"
|
||||||
|
"(realize (p v))")
|
||||||
|
"realization is missing a method of"))
|
||||||
|
(test-assert "nor is a comment"
|
||||||
|
(reports? (string-append "(record v ((x int)))"
|
||||||
|
"(spec (p T) (fn s ((a (* const T))) int\n"
|
||||||
|
" ;; must be implemented\n"
|
||||||
|
" ))"
|
||||||
|
"(realize (p v))")
|
||||||
|
"realization is missing a method of"))
|
||||||
|
(test-assert "a documented default is still a default"
|
||||||
|
(emits? (string-append "(record v ((x int)))"
|
||||||
|
"(spec (p T) (fn s ((a (* const T))) int \"doc\" (return 1)))"
|
||||||
|
"(realize (p v))")
|
||||||
|
"/* doc */"))
|
||||||
(test-assert "a method the spec has not got is refused"
|
(test-assert "a method the spec has not got is refused"
|
||||||
(reports? (string-append "(record v ((x int)))"
|
(reports? (string-append "(record v ((x int)))"
|
||||||
"(spec (p T) (fn s ((a (* const T))) void))"
|
"(spec (p T) (fn s ((a (* const T))) void))"
|
||||||
|
|||||||
Reference in New Issue
Block a user