racket / racket/typed-racket

(struct-type-info (eval 'struct:st)) fails with raco test (works with racket and drracket)

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

Nobody has claimed this yet.

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

Description

What version of Racket are you using?

6.7.0.1

What program did you run?
#lang typed/racket
(require (for-syntax racket/struct-info))

(module m typed/racket
  (provide (struct-out st))
  (struct st () #:transparent))

(require 'm)

(define vr (#%variable-reference))

(define eval-ty
  (call-with-values (λ () (eval 'struct:st
                                (variable-reference->namespace vr)))
                    (λ l l)))
(define ty (assert (car eval-ty) struct-type?))

(struct-type-info ty)
If you got an error message, please include it here.

The program fails with the following error using raco test, but otherwise works fine with racket and drracket.

raco test: "/tmp/ta.rkt"
        struct:st: contract violation
  Attempted to use a struct type reflectively in untyped code: #<struct-type:st>
  in: "struct-type/c"
  contract from: (/tmp/ta.rkt m)
  blaming: /tmp/ta.rkt
   (assuming the contract is correct)
  at: /tmp/ta.rkt:7.10
  context...:
   /nix/store/swpi9mnzfff6jv5baapa8cpr46z31p1b-racket-6.7.0.1/share/racket/collects/racket/contract/private/blame.rkt:159:0: raise-blame-error16
   /tmp/ta.rkt: [running body]

Is there any workaround to get this to work with raco test?


Context:

I need to do this for my delay-pure library, which adds non-cached pure promises to Typed Racket. The library restricts what functions can be called within a pure promise, and among other things only allows constructors for immutable structs. It works by checking the value of all free identifiers within the promise's body. When struct-constructor-procedure? returns #t for one such value, I use object-name and try to see if there is a struct type with that name within the namespace where the promise is created. I then use the information provided by struct-type-info to check whether the struct type is immutable or not (using code from Greg Hendershott's egal, ported to Typed Racket).

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

Start by running the /tmp/ta.rkt reproducer with raco test, then compare it with racket and drracket. Trace the interaction between eval, variable-reference->namespace, struct-type-info, and the typed/racket module boundary; done means the reproducer works consistently under raco test or a documented workaround is identified.

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
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.