Type mismatch with #!optional pasted by phm on Sun Oct 18 23:19:23 2026

    (: bytevector-fill! (bytevector fixnum
                                    #!optional fixnum fixnum
                                    ->))
    (define (bytevector-fill! bv b8 #!optional (start 0)
                                               (end (bytevector-length bv)))

minimal example added by phm on Sun Oct 18 23:22:20 2026

(import (chicken base) (chicken foreign) (chicken condition) (chicken type)
        (only (scheme base) make-bytevector bytevector-length))
    (define memset
      (foreign-lambda* void ((bytevector bv)
                             (unsigned-byte b8)
                             (size_t start)
                             (size_t end))
        "memset(bv+start, b8, end-start);"))

    (define (raise-bounds-error who arguments)
      (raise (condition `(exn location ,who
                              message "invalid bounds"
                              arguments ,arguments))))

    (: bytevector-fill! (bytevector fixnum
                                    #!optional fixnum fixnum
                                    ->))
    (define (bytevector-fill! bv b8 #!optional (start 0)
                                               (end (bytevector-length bv)))
      (unless (<= 0 start end (bytevector-length bv))
        (raise-bounds-error 'bytevector-fill! (list bv start end)))
      (memset bv b8 start end))

(define bv (make-bytevector 10))
(bytevector-fill! bv -1 0 5)
(display bv)
(newline)

#|
Compile with csc -O3

Warning: Invalid assignment
  At the toplevel,
  In assignment:

    (set! bytevector-fill! (lambda (bv b8 . rest) (let (...) (let ... ...))))

  Variable `bytevector-fill!' is assigned invalid value.

  The assigned value has this type:

    (* * #!rest -> undefined)

  The declared type of `bytevector-fill!' is:

    (bytevector fixnum #!optional fixnum fixnum ->)
|#