racket / scribble

Other
201 stars 92 forks source link

contract blame fix? #259

Closed jbclements closed 4 years ago

jbclements commented 4 years ago

I'm not sure whether this is the kind of thing that merits an issue, but... running this code

#lang scribble/manual

@defthing[#:kind 'type]{

abrc
}

results in an error that blames scribble code, rather than the user. To wit:

racket-cs/racket/share/pkgs/scribble-lib/scribble/private/manual-proc.rkt:1059:10: make-paragraph: contract violation
  expected: content?
  given: 'type
  in: the 2nd argument of
      (-> style? content? paragraph?)
  contract from: 
      <pkgs>/scribble-lib/scribble/core.rkt
  blaming: <pkgs>/scribble-lib/scribble/struct.rkt
   (assuming the contract is correct)
  at: <pkgs>/scribble-lib/scribble/core.rkt:252.2

Do we care?

rfindler commented 4 years ago

My syntax-parse-fu is not up to snuff. I thought that this would have fixed the error:

 (define-splicing-syntax-class kind-kw
   #:description "#:kind keyword"
   (pattern (~optional
             (~seq #:kind (~var kind (expr/c #'string? #:name "#:kind argument")))
             #:defaults ([kind #'#f]))))

replacing this definition of kind-kw, but I'm not seeing a new error when I make that change. Maybe @jeapostrophe or @rmculpepper wouldn't mind chiming in?

rmculpepper commented 4 years ago

You need to use the c attribute computed by expr/c. Here's how I would write it:

(define-splicing-syntax-class kind-kw
  #:attributes (kind) ;; Expr[String/#f]
  #:description "#:kind keyword"
  (pattern (~optional (~seq #:kind k))
           #:declare k (expr/c #'string? #:name "#:kind argument")
           #:with kind #'(~? k.c #f)))

Based on a quick glance, the rest of the module seems to just use the kind attribute, so I changed that to get the contract-wrapped expression.

rmculpepper commented 4 years ago

Sorry, I shouldn't have used #:declare, since that change is unrelated to the fix. Here's the same code without #:declare:

(define-splicing-syntax-class kind-kw
  #:attributes (kind) ;; Expr[String/#f]
  #:description "#:kind keyword"
  (pattern (~optional (~seq #:kind (~var k (expr/c #'string? #:name "#:kind argument"))))
           #:with kind #'(~? k.c #f)))

The #:attributes line isn't strictly necessary here either, but it's useful documentation.

rfindler commented 4 years ago

Thanks, @rmculpepper !