racket / racket/typed-racket

(Struct st) does not work with polymorphic structs

Open
#451 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
(struct (A) s1 ([f : A]))
(struct (A B) s2 s1 ([g : B]))
(struct s3 ([h : Symbol]))

(ann ((inst s2 Number String) 1 "b") (Struct s1)) ;; Error
(ann ((inst s2 Number String) 1 "b") (Struct s2)) ;; Error
(ann ((inst s2 Number String) 1 "b") (Struct (s1 Number))) ;; Works
(ann ((inst s2 Number String) 1 "b") (Struct (s2 Number String))) ;; Works
(ann (s3 'x) (Struct s3)) ;; Works
What should have happened?

The docs explicitly state that:

(Struct st) is a type which is a supertype of all instances of the potentially-polymorphic structure type st. Note that structure accessors for st will not accept (Struct st) as an argument.

so the first two cases should work, but they throw an error instead.

If you got an error message, please include it here.
Type Checker: parse error in type;
 expected a structure type for argument to Struct
  given: s1 in: (Struct s1)

and

Type Checker: parse error in type;
 expected a structure type for argument to Struct
  given: s2 in: (Struct s2)

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 Typed Racket program in the issue and compare the two failing (Struct s1) and (Struct s2) annotations with the working parameterized forms. Done means the unparameterized polymorphic structure annotations are accepted as documented, while the existing working examples continue to pass.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.