Terminate typechecking on cyclic lists.

Closes PR 13687.

original commit: b8ab1334d9192720ebb6a37e311880f158276d8b
This commit is contained in:
Eric Dobson 2013-04-12 21:33:07 -07:00
parent 28a898f4fe
commit 632b14c736
2 changed files with 16 additions and 5 deletions

View File

@ -0,0 +1,8 @@
#lang typed/racket
(define-type CyclicSymbols (Rec X (Pair Symbol X)))
(: mycar : (CyclicSymbols -> Symbol))
(define (mycar lst)
(car lst))

View File

@ -7,6 +7,7 @@
racket/match
(types resolve)
(contract-req)
racket/set
(for-syntax racket/base syntax/parse racket/list))
(provide Listof: List: MListof:)
@ -27,11 +28,13 @@
#'(app untuple (? values elem-pats))])))
(define (untuple t)
(match (resolve t)
[(Value: '()) null]
[(Pair: a b) (cond [(untuple b) => (lambda (l) (cons a l))]
[else #f])]
[_ #f]))
(let loop ((t t) (seen (set)))
(and (not (set-member? seen (Type-seq t)))
(match (resolve t)
[(Value: '()) null]
[(Pair: a b) (cond [(loop b (set-add seen (Type-seq t))) => (lambda (l) (cons a l))]
[else #f])]
[_ #f]))))
(define-match-expander MListof:
(lambda (stx)