Skip to content

msgpack failure #625

Closed
Closed
@bennn

Description

@bennn

cc @samth

Description

The msgpack package fails to build with the current TR release candidate. The source compiles, but test programs written in #lang racket do not. For example:

#lang racket/base
(require msgpack)
unpack

Error message:

foo.rkt:3:0: Type Checker: could not convert type to a contract;
 required a flat contract but generated a chaperone contract
  identifier: unpack
  type: (-> Input-Port Packable)
  in: unpack

The type for unpack is:

(: unpack (-> Input-Port
              (U Void Boolean Integer Real String Bytes (Vectorof Packable) (Listof Packable) (HashTable Packable Packable) Ext)))

where Packable is:

(define-type Packable
  (U Void
     Boolean
     Integer
     Real
     String
     Bytes
     (Vectorof Packable)
     (Listof Packable)
     (HashTable Packable Packable)
     Ext))

Minimal Example

The TR error message seems to be due to the HashTable type in Packable; here's a tiny program the raises a similar exception:

#lang racket/base

(module t typed/racket/base
  (provide f)

  (define-type T
    (HashTable (Vectorof Integer) Symbol))

  (: f (-> Symbol T))
  (define (f x)
    (hash '#(1) x)))

(require 't)

f

Error message (on Racket v6.10.1 or earlier):

bar.rkt:15:0: Type Checker: could not convert type to a contract;
 required a flat contract but generated a chaperone contract
  identifier: f
  type: (-> Symbol T)
  in: f

The program runs if the type for f is (-> Symbol (U Integer T)) because that type gets converted to a contract like (-> Symbol any/c)

Diagnosis

Since (hash (vector 1) 'a) is valid, the problem is likely the constraint in static-contracts/combinators/structural.rkt that hashtable keys must be flat:

  ((hash/sc (#:invariant #:flat) (#:invariant)) hash/c #:chaperone)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions