racket / typed-racket

Typed Racket

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unsoundness with require/typed

bennn opened this issue · comments

What version of Racket are you using?

6.10.1

What program did you run?

I sent a vector from one typed module to another, through a require/typed.
The require/typed let me change the vector's element type.

#lang racket/base

(module a typed/racket/base
  (provide f v)

  (: v (Vector (Boxof Natural)))
  (define v (vector (box 0)))

  (: f (-> Natural))
  (define (f)
    (unbox (vector-ref v 0))))

(module b typed/racket/base
  (require/typed (submod ".." a)
    (f (-> Natural))
    (v (Vectorof Integer)))

  (vector-set! v 0 0)
  (f))

(require 'b)

What should have happened?

Some kind of Racket error. Suggestions:

  • static type error, (Vectorof Integer) not compatible
  • runtime error, expected box got 0

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

segmentation fault

I'm not sure how to go about fixing this. Maybe the easiest is to disallow / discourage a require/typed between typed modules.

Wait, what's actually going on here? require/typed of a typed module ought to work fine (Robby and I even wrote a paper about it).

Ah, the problem is that a's contracts aren't applied, just b's.

I think the solution is to treat that as not a typed module requiring a, so require/typed needs to arrange for the typed-context? flag to be #f.