assignment to identifiers bound by for-like forms can break invariants
Nobody has claimed this yet.
- Dominant language
- Racket
- Stars
- 5.2k
- Forks
- 698
- Avg merge
- 18h 34m
- Merged PRs (30d)
- 5
Description
Identifiers bound by for- and for/fold-like forms—for both accumulators and sequence elements—can be set!. Assigning to these variables can break invariants or expose implementation details of a for-like form or for-clause transformer (as in define-sequence-syntax).
Some examples:
-
->#lang racket (for/lists (acc) ([v (in-range 2)]) (unless (zero? v) (set! acc 'bad)) v)racket/private/for.rkt:1963:23: reverse: contract violation expected: list? given: '(1 . bad) -
->#lang racket (require (for-syntax syntax/parse)) (define-sequence-syntax in-my-naturals (λ () #'in-naturals) (syntax-parser [[(n) (_)] #'[(n) (:do-in ([(n) 0]) #t ([n n]) #t ([(n) n]) #t #t ((add1 n)))]])) (for/list ([i (in-my-naturals)] #:when (< i 3)) (set! i 'bad))add1: contract violation expected: number? given: 'bad
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing both examples and inspect racket/private/for.rkt around the reported line, along with the for-like and for-clause transformer behavior shown in the issue. Determine the intended handling of set! on accumulator and sequence-element bindings, then add coverage demonstrating that these assignments cannot break the form's invariants or expose implementation details.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100