typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

coverage testing broken for some uses of vector-set!

Open jbclements opened this issue 2 years ago • 2 comments

What version of Racket are you using?

8.8.0.8--2023-02-23(-/f) [cs].

What program did you run?

#lang typed/racket

(: my-vector-set! (All (T) ((Vectorof T) Natural T -> Void)))
(define (my-vector-set! vec idx newval)
  (vector-set! vec idx newval))

(define v (vector 1 2 3))

(vector-set! v 0 1234)
(my-vector-set! v 0 1234)
(vector-set! v (ann 0 Natural) 1234)

What should have happened?

The program should have shown complete coverage.

If you got an error message, please include it here.

Instead, the first use of vector-set! is shown as not having coverage. Running the macro expander indicates that this use of vector-set! is expanded into a conditional which calls the native vector-set! only if the vector is immutable, and an unsafe version otherwise. I conjecture that fixing this is a matter of ensuring that the application of the unsafe vector mutator is given the source location of the original application. It looks like this might be on or near line 87 of vector.rkt, but I see a conspicuous lack of similar source location annotations in this code, so perhaps this is actually a larger problem.

Either way, there are workarounds (albeit cryptic ones), as this snippet demonstrates.

jbclements avatar Mar 03 '23 21:03 jbclements

Bump, a new generation of students are running into this...

jbclements avatar May 21 '24 20:05 jbclements

I'm one of the afformentioned students running into this problem.

  • using Racket v8.13
  • generating coverage report using raco cover
  • (ann 0 Natural) did fix the problem, but (ann 0 Index) did not 🤔

dltompki avatar May 28 '24 05:05 dltompki