Skip to content

Commit 4ab0b00

Browse files
shhyousorawee
authored andcommitted
Fix defstruct with an empty list of field options
1 parent bb1ef38 commit 4ab0b00

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

scribble-lib/scribble/private/manual-proc.rkt

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"manual-method.rkt"
1818
"manual-ex.rkt"
1919
"on-demand.rkt"
20+
racket/match
2021
racket/string
2122
racket/list
2223
racket/contract
@@ -897,10 +898,15 @@
897898
(append (if (pair? name) name (list name))
898899
(map field-name fields)))
899900
(map (lambda (f)
900-
(if (pair? (car f))
901-
(+ 3 2 (string-length (keyword->string
902-
(cadar f))))
903-
0))
901+
(match (car f)
902+
[(? symbol?) 0]
903+
[(list name) 2] ;; the extra [ ]
904+
[(list* name field-opts)
905+
;; '[' ']'
906+
(apply + 2
907+
(for/list ([field-opt (in-list field-opts)])
908+
;; and " #:"
909+
(+ 3 (string-length (keyword->string field-opt)))))]))
904910
fields)))])
905911
(cond
906912
[(and (short-width . < . max-proto-width)

scribble-test/tests/scribble/docs/manual-ex.rkt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
(define-struct pt (x y))
2222
(struct pn (x y))
23+
(struct counter (name [count #:mutable]))
2324

2425
(define v 10)
2526

scribble-test/tests/scribble/docs/manual.scrbl

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ A function, again, not a link target, documented to return @racket[10] using a d
9999

100100
@defstruct[#:link-target? #f pt ([x real?] [y real?]) #:mutable]{A mutable structure type with extra name, again.}
101101

102+
@defstruct*[#:link-target? #f counter ([name symbol?] [(count) exact-nonnegative-integer?])]{A struct with an (empty) list of field options.}
103+
104+
@defstruct*[counter ([name symbol?] [(count #:mutable) exact-nonnegative-integer?])]{Another struct with a mutable field.}
105+
106+
@defstruct*[#:link-target? #f counter ([name symbol?] [(count #:auto) exact-nonnegative-integer?])]{A struct with an automatic field.}
107+
108+
@defstruct*[#:link-target? #f counter ([name symbol?] [(count #:auto #:mutable) exact-nonnegative-integer?])]{A struct with both.}
109+
102110
@defstruct[a-struct-with-an-extremely-long-name-and-no-fields ()]{Used to raise error, taking car of empty fields list. Reported by Carlos Lopez, 2017-03-11.}
103111

104112

scribble-test/tests/scribble/docs/manual.txt

+24
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,30 @@ A structure type with extra name, again.
248248

249249
A mutable structure type with extra name, again.
250250

251+
(struct counter (name [count]))
252+
  name : symbol?
253+
  count : exact-nonnegative-integer?
254+
255+
A struct with an (empty) list of field options.
256+
257+
(struct counter (name [count #:mutable]))
258+
  name : symbol?
259+
  count : exact-nonnegative-integer?
260+
261+
Another struct with a mutable field.
262+
263+
(struct counter (name [count #:auto]))
264+
  name : symbol?
265+
  count : exact-nonnegative-integer?
266+
267+
A struct with an automatic field.
268+
269+
(struct counter (name [count #:auto #:mutable]))
270+
  name : symbol?
271+
  count : exact-nonnegative-integer?
272+
273+
A struct with both.
274+
251275
(struct a-struct-with-an-extremely-long-name-and-no-fields ()
252276
    #:extra-constructor-name
253277
    make-a-struct-with-an-extremely-long-name-and-no-fields)

0 commit comments

Comments
 (0)