racket-collections
racket-collections copied to clipboard
Bug: conj* and extend* for collections that aren't sequences
If a struct type implements gen:collection but not gen:sequence, then conj* and extend* result in a contract error.
(struct bag (contents)
#:transparent
#:methods gen:collection
[(define (conj col elem)
(bag (cons elem (bag-contents col))))])
main.rkt> (conj (bag (list 1 2 3)) 4)
(bag '(4 1 2 3))
main.rkt> (extend (bag (list 1 2 3)) (list 4))
(bag '(4 1 2 3))
main.rkt> (conj* (bag (list 1 2 3)) 4)
; conj*: broke its own contract
; promised: sequence?
; produced: (bag '(4 1 2 3))
; in: the range of
; (->* (collection?) #:rest any/c sequence?)
; contract from:
; <pkgs>/collections-lib/data/collection/collection.rkt
; blaming: <pkgs>/collections-lib/data/collection/collection.rkt
; (assuming the contract is correct)
; at: <pkgs>/collections-lib/data/collection/collection.rkt:44.3
; Context:
; .../private/blame.rkt:347:0 body of "/Users/siddhartha/work/lisp/racket/generator-util/main.rkt"
; .../contract/combinator.rkt:324:9
; .../private/arrow-val-first.rkt:486:18
; .../racket/repl.rkt:11:26
main.rkt> (extend* (bag (list 1 2 3)) (list 4))
; extend*: broke its own contract
; promised: sequence?
; produced: (bag '(4 1 2 3))
; in: the range of
; (->*
; (collection?)
; #:rest
; (listof sequence?)
; sequence?)
; contract from:
; <pkgs>/collections-lib/data/collection/collection.rkt
; blaming: <pkgs>/collections-lib/data/collection/collection.rkt
; (assuming the contract is correct)
; at: <pkgs>/collections-lib/data/collection/collection.rkt:43.3
; Context:
; .../private/blame.rkt:347:0 body of "/Users/siddhartha/work/lisp/racket/generator-util/main.rkt"
; .../contract/combinator.rkt:324:9
; .../private/arrow-val-first.rkt:486:18
; .../racket/repl.rkt:11:26