Repository: racket/racket

Issue #1652: Contracted elements in signatures not working (since at least Racket 6.4)
Created: 2017-03-31T22:06:41Z
This program:
#lang racket

(module sig racket
  (provide contracted-toy-factory^)
  (define-signature contracted-toy-factory^
    (toy?
     (contracted
      [toy-color  (-> toy? symbol?)]))))

(module unit racket
  (require (submod ".." sig))
  (define-unit contracted-simple-factory@
    (import)
    (export contracted-toy-factory^)
    (define (toy-color n) 'red)
    (define (toy? n) #t)))

Runs in Racket 6.2, but in Racket 6.4+ gives the following error:
toy?: unbound identifier in module
  context...:
  other binding...:
  other binding...:
  other binding...:
  other binding...:
  other binding...: in: toy?

Duplicate issue #2316: Contracts on unit bindings that refer to other unit bindings are broken on sets-of-scopes expander
Created: 2018-10-16T18:54:13Z
This program fails to compile on Racket v6.12 and v7.0, but succeeds on v6.2.1:
#lang racket/base

(module sig racket/base
  (require racket/contract
           racket/unit)

  (provide foo^)

  (define-signature foo^
    [(contracted
      [foo? flat-contract?]
      [make-foo (-> foo?)])]))

(module impl racket/base
  (require racket/unit
           (submod ".." sig))

  (provide foo@)

  (define-unit foo@
    (import)
    (export foo^)
    (define (foo? x) #f)
    (define (make-foo) #f)))

(require racket/unit
         'impl)

(define-values/invoke-unit/infer foo@)
(make-foo)
Specifically, on the sets-of-scopes expander, it fails with the following error message:
unit-with-contract.rkt:12:20: foo?: unbound identifier
  in: foo?
  context...:
   #(422 module) #(425 module sig) #(1160 macro) #(1686 module impl)
   #(1722 use-site) #(1778 local) #(1779 letrec-body) #(1784 intdef)
   #(1796 local) #(1797 intdef) #(1800 local) #(1801 intdef)
   #(1803 local) #(1806 intdef) #(1809 local) #(1810 intdef)
   #(1811 local) #(1812 intdef) #(1814 local) #(1815 letrec-body)
   #(1816 intdef) #(1817 local) #(1818 letrec-body) #(1821 intdef)
   #(1841 intdef) #(1868 local) #(1869 letrec-body) #(1903 intdef)
   #(1906 local) #(1907 intdef) [common scopes]
  other binding...:
   local
   #(1820 macro) #(1838 macro) #(1841 intdef) #(1868 local)
   [common scopes]
  other binding...:
   local
   #(1683 module) #(1686 module impl) #(1722 use-site) #(1778 local)
   #(1779 letrec-body) #(1784 intdef) #(1796 local) #(1797 intdef)
   #(1800 local) #(1801 intdef) #(1803 local) #(1806 intdef)
   #(1809 local) #(1810 intdef) #(1811 local) #(1812 intdef)
   #(1814 local) #(1815 letrec-body) #(1816 intdef) #(1817 local)
   #(1818 letrec-body) #(1821 intdef) #(1841 intdef) #(1868 local)
   [common scopes]
  other binding...:
   local
   #(1683 module) #(1686 module impl) #(1722 use-site) #(1778 local)
   #(1779 letrec-body) #(1784 intdef) #(1796 local) #(1797 intdef)
   #(1800 local) #(1801 intdef) #(1803 local) #(1806 intdef)
   #(1809 local) #(1810 intdef) #(1811 local) #(1812 intdef)
   #(1814 local) #(1815 letrec-body) #(1816 intdef) #(1817 local)
   #(1818 letrec-body) #(1821 intdef) #(1841 intdef) [common scopes]
  other binding...:
   local
   #(1820 macro) #(1838 macro) #(1841 intdef) [common scopes]
  other binding...:
   local
   #(1683 module) #(1686 module impl) #(1722 use-site) #(1778 local)
   #(1779 letrec-body) #(1784 intdef) #(1796 local) #(1797 intdef)
   #(1800 local) #(1801 intdef) #(1803 local) #(1806 intdef)
   #(1809 local) #(1810 intdef) #(1811 local) #(1812 intdef)
   #(1814 local) #(1815 letrec-body) #(1816 intdef) #(1817 local)
   #(1818 letrec-body) #(1821 intdef) [common scopes]
  common scopes...:
   #(1819 intdef)
  location...:
   unit-with-contract.rkt:12:20
  context...:
   do-raise-syntax-error
   expand-implicit
   for-loop
   [repeats 1 more time]
   finish-bodys
   for-loop
   [repeats 1 more time]
   finish-bodys
   loop
   [repeats 3 more times]
   for-loop
   finish-bodys
   loop
   for-loop
   finish-bodys
   loop
   ...

But on Racket v6.2.1, it successfully compiles and raises the following contract violation at runtime:
make-foo: broke its contract
  promised: foo?
  produced: #f
  in: the range of
      (-> foo?)
  contract from: (unit foo@)
  blaming: (unit foo@)
   (assuming the contract is correct)
  at: /private/tmp/unit-with-contract.rkt:12.7
  context...:
   /Applications/Racket v6.2.1/collects/racket/contract/private/blame.rkt:143:0: raise-blame-error16
   /private/tmp/unit-with-contract.rkt: [running body]

Closing comment (2018-10-16T19:13:18Z): Closing as duplicate of #1652.