racket / racket/typed-racket

define-predicate fails to define predicate for Refine

Open
#960 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

What version of Racket are you using?

Racket 7.7

What program did you run?
#lang typed/racket
(define-type Rational (U Integer (Pair Rational Non-Zero-Rational)))
(define-type Zero-Rational (U Zero (Pair Zero-Rational Non-Zero-Rational)))
(define-type Non-Zero-Rational (Refine [num : Rational] (! num Zero-Rational)))

(define-predicate rat? Rational)

(: make-rational (case-> [-> Rational Non-Zero-Rational Rational]
                         [-> Rational Rational]))
(define make-rational
  (case-lambda
    [(r) r]
    [(r1 r2)
     (cons r1 r2)]))

(displayln (rat? (make-rational 3 2)))
What should have happened?

#t

If you got an error message, please include it here.
car: contract violation
  expected: pair?
  given: #f
  context...:
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/static-contracts/instantiate.rkt:90:2: loop
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/static-contracts/instantiate.rkt:80:0: compute-defs
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/static-contracts/instantiate.rkt:109:0: compute-constraints
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/private/type-contract.rkt:230:0: get-max-contract-kind
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/private/type-contract.rkt:438:10: for-loop
   f934
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/name.rkt:77:0: register-name-sc
   f952
   f794
   /usr/share/racket/collects/racket/private/map.rkt:40:19: loop
   /usr/share/racket/collects/racket/private/map.rkt:35:13: map
   f1476
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/name.rkt:77:0: register-name-sc
   f952
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/private/type-contract.rkt:287:2
   /usr/share/racket/pkgs/typed-racket-lib/typed-racket/private/type-contract.rkt:84:0: generate-contract-def

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided typed/racket reproduction first. Trace contract generation through typed-racket/static-contracts/instantiate.rkt, private/type-contract.rkt, and static-contracts/combinators/name.rkt, focusing on Refine handling. Done means define-predicate compiles without the car contract violation and rat? returns #t for the constructed rational.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.