"missing type for identifier" / expression's type changes, with weird combination of requires and eval

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

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Domain
compilers

Research direction

Start with the supplied typed/racket reproduction at the REPL, focusing on the baz and bar modules, their begin-for-syntax blocks, eval call, and phase-shifted requires. Compare the first and repeated expressions, then the renamed-identifier and mylib/empty variants; done means repeated evaluations preserve the inferred type and no longer report a missing type for v or produce Any.

Written by the indexing model from the issue text.

Description

What version of Racket are you using?

6.9.0.1

What program did you run?
#lang typed/racket
(module baz racket/base
  (require (for-syntax racket/base))
  (begin-for-syntax
    (eval '0
          (module->namespace 'racket/private/sc))))
(module bar
  racket/base
  (require (for-meta -2 (submod ".." baz))
           ;; Bug also occurs with typed/racket/no-check here:
           (for-syntax typed/racket)))
;; Main module:
(require (for-syntax 'bar))
;; At the REPL of the main module:
#;(let ([v 1]) v) ;; First try works
#;(let ([v 1]) v) ;; Error on second try
;; Type Checker: missing type for identifier;
;; consider adding a type annotation with `:'
;;  identifier: v in: v

Splitting the file into several separate files still triggers the bug (but if I try to inline the require statements from bar into foo, shifting everything one meta-level up, then the bug stops occurring). If the second try renames v to w, then it works fine, but later uses of v or w trigger this bug.

If I use my type-expander in module bar, then I can trigger a slightly different bug: the type of the result of ((λ #:∀ (A) (x) x) 1) is Integer on the first try, and becomes Any on the second and later tries. If the second try renames x to t, then it works fine, but later uses of x or y trigger this bug.

#lang typed/racket

(module baz racket/base
  (require (for-syntax racket/base)
           (for-meta 2 racket/base))
  (begin-for-syntax
    (begin-for-syntax
      (eval '0
            (module->namespace 'racket/private/sc)))))

(module bar type-expander/lang
  (require (for-meta -2 (submod ".." baz))))

;; Main module:
(require 'bar)
;; At the REPL of the main module:
#;((λ #:∀ (A) (x) x) 1) ;; Type: Integer
#;((λ #:∀ (A) (x) x) 1) ;; Type: Any
;; More meaningful example of usage:
#;(let #:∀ (A ...) ([v : (List (Pairof Any A) ...) (list '(0 . 1))]) v) ;; (List (Pairof Zero One))
#;(let #:∀ (A ...) ([v : (List (Pairof Any A) ...) (list '(0 . 1))]) v) ;; (List (Pairof Any One))

Note that these bugs do not depend on the use of racket/private/sc. If I change it to mylib/empty, where the empty.rkt only contains (module quux '#%kernel), the bugs still occur.

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

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.

More from racket/typed-racket

All issues in racket/typed-racket

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.