Skip to content

Unsoundness from stateful #:opaque predicates #457

Open
@AlexKnauth

Description

@AlexKnauth
What version of Racket are you using?

I'm using version 6.7.0.1

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

I didn't get an error message. I added the number 16 to the byte string #"abcdefg" and got a box pointing to the number 3136 as the answer.

What should have happened?

I'm not sure. Maybe occurrence typing has to work differently for #:opaque predicates?

What program did you run?
#lang typed/racket

(module untyped racket
  (provide x? reset!)
  (define b (make-parameter #true))
  (define (x? x)
    (cond [(b) (b #false) #true]
          [else #false]))
  (define (reset!) (b #true)))

(require/typed 'untyped
               [#:opaque X x?]
               [reset! (-> Void)])

(: ->false : (All (T) [Any -> Boolean : #:+ T]))
(define (->false v) #false)

(: transmute : (All (T) Any -> T))
;; This ends up always returning v
(define (transmute v)
  (reset!)
  ;; (x? v) returns #true the first time
  (if (or (x? v) ((inst ->false T) v))
      (if (not (x? v)) ; but #false the second time
          v
          (error "this never happens"))
      (error "this never happens")))

(+
           #b00000000000000000000000000010000
           (transmute ;(inst transmute Positive-Index)
            (string->bytes/utf-8 "abcdefg")))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions