From 06bd5d36af88a99d2f76b65c073da21d63b5ee1f Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Thu, 1 May 2014 15:57:19 -0400 Subject: [PATCH] Don't track syntax with unknown source locations Avoids recording original syntaxes with a source or position of #f, since these are usually intermediate syntax pairs that don't correspond to actual source syntax. For example, in a (#%module-begin . rst) in a submodule, the underlying pair may contain an identifier and a cdr that is a syntax object. That cdr will have #f source and position and also does not correspond to any source syntax. Leaving such syntax objects in the table means there are spurious hits later when a syntax object with an unknown source location is looked up. Closes PR 14389 --- pkgs/typed-racket-pkgs/source-syntax/source-syntax.rkt | 7 ++++++- .../tests/typed-racket/fail/pr14389.rkt | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/pr14389.rkt diff --git a/pkgs/typed-racket-pkgs/source-syntax/source-syntax.rkt b/pkgs/typed-racket-pkgs/source-syntax/source-syntax.rkt index 2dedd0dd5e..bb641cfef2 100644 --- a/pkgs/typed-racket-pkgs/source-syntax/source-syntax.rkt +++ b/pkgs/typed-racket-pkgs/source-syntax/source-syntax.rkt @@ -22,7 +22,12 @@ ;; build `syntax-locs` (let loop ([stx orig]) - (when (syntax? stx) (hash-set! syntax-locs (syntax-loc stx) stx)) + (when (and (syntax? stx) + ;; avoid spurious hits in the table from syntaxes + ;; that have no useful source information + (and (syntax-source stx) + (syntax-position stx))) + (hash-set! syntax-locs (syntax-loc stx) stx)) (let ([stx (if (syntax? stx) (syntax-e stx) stx)]) (when (pair? stx) (loop (car stx)) (loop (cdr stx))))) diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/pr14389.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/pr14389.rkt new file mode 100644 index 0000000000..bfb78b0792 --- /dev/null +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/fail/pr14389.rkt @@ -0,0 +1,10 @@ +#; +(exn-pred (regexp-quote "in: (for/flvector")) +#lang typed/racket/base + +(require racket/flonum) +(module+ test + (require typed/rackunit) + (define (from upto) + (for/flvector ([i (in-range from upto)]) + 0.0)))